Question

I want to change the way a validation message appears to the user in my nopCommerce web application. Currently, it appears as so:

enter image description here

I want to change that, so that if and when the login credentials are incorrect, the input fields get a red border, and the text [ wrong credentials ] to be set as Placeholder for the input fields.

I tried disabling the code:

@Html.ValidationSummary(true, T("Account.Login.Unsuccessful").Text)

But that just took away all validation feedback. How can I achieve what I mentioned above?

Was it helpful?

Solution

Here is the complete Updated code

CSS

.validation-error
{
    border: 1px solid #ff0000;
    background-color: #ffeeee;
}

Jquery code to check the login using $.ajax

$(function () {
        $('#btnLogin').click(function (e) {
            var email = $('#Email').val(); // this your username textbox value
            var password = $('#Password').val(); // this is your password textbox value
            var postdata = 
            {
                "Email": email,
                "Password": password
            };
            $.ajax({

                tyep: 'POST',
                url: '@Url.Action("LogIN","Account")', // your controller action will be called to check for the login details
                data: postdata, // this data you have to post to controller for validation
                success: function(value) { // if ajax call complete, controller action will return boll value true here 
                     if(valeu) {
                    $('#divLoginError').addClass("validation-error"); // this will add class class to your textboxes with red broder
                    $('divLoginError').html('Please check your username / password');
                     }
                  },
                error: function(errorData) // if any error while calling Ajax. this method is gonna call
                {
                    $('#divLoginError').show().html(errorData);
                }
            });

        });
    });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top