0

Currently I am using Unobtrusive validation on my site. So right now, when a form element is not valid, I display the error message (Configured from an attribute on the server) . What I want to do now is to also change the label and border of the text box so they go red when a form element is invalid, or green when valid.

Are there any extra attributes I can add to make this happen, or do I need to create my own validators that inherit from the standard ones, but add in the extra client side functionality?

Matt
  • 1,596
  • 2
  • 18
  • 32
  • No, there are no attributes to to change a the label (you would need javascript for that). But the textbox can be styled based on the class names generated - `valid` and `input-validation-error` –  Jan 27 '17 at 12:17
  • Thanks. So if I wanted to display little tick and cross symbols, and change the label colour as well, I either need to create my own custom validators to register new unobtrusive validator js, ditch the unobtrusive approach. Time to get thinking :-) – Matt Jan 27 '17 at 12:40
  • Creating 'custom validators' wont do it (unless you re-write `jquery.validate.js` and `jquery.validate.unobtrusive.js` as well) –  Jan 27 '17 at 12:45
  • Ok, that narrows it down nicely then, thanks! – Matt Jan 27 '17 at 12:48
  • See: http://stackoverflow.com/questions/18754020/bootstrap-3-with-jquery-validation-plugin. It concerns applying Bootstrap styles when there's validation errors. You didn't specify if you're using Bootstrap or not, but you should be able to apply the same code to add whatever classes and such you need in your specific scenario. – Chris Pratt Jan 27 '17 at 17:47
  • I'l check it out, thanks – Matt Jan 31 '17 at 10:21

0 Answers0