0

Is there a way to have the field to be validated in red when the input is considered as invalid.

I don't want to use the Html.ValidationMessageFor, because I don't wan't to have a message with it(it's only for "required" fields).

Thanks you for the help

2 Answers 2

1

It's already built into MVC (there are CSS classes for it).

Change the field-validation-error in site.css to include display:none.

input-validation-error controls how the text boxes look like.

That will only show red borders for invalid fields.

Sign up to request clarification or add additional context in comments.

1 Comment

Shame on me :(. Designer gaves me a css without this class, and I didn't checked it was present, so everything was working, but I wasn't having the correct css :/. It also seems I don't need to add the Html.ValidationMessageFor to get this css.
0

If you use jquery, you can do something like

$('input#myField').on('blur', function(){ //or keyup/keydown/keypress
  var myVal = $(this).val();
  bool isValid = isMyFieldValid(myVal);
  if (!isValid) {
    $(this).addClass('error');
    return false;
  }
  return true;
});

edit: just noticed you wanted a class added or not

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.