Semantic-UI icon indicating copy to clipboard operation
Semantic-UI copied to clipboard

Ability to Run a Invalid Call Back on a Rule

Open bryanlittlefield opened this issue 11 years ago • 2 comments

I needed to run a call back if a specific field was invalid. Maybe I am missing something but it seems that I could only run the callback on all the fields , iterate through them and check if it was the field that I needed the callback for (modal pop).

I attached an a very dumbed down version of it via JS Fiddle to show the round about way I achieved this but I was wondering if there was either a better way to do this via rules or if this is a feature that could be added

http://jsfiddle.net/c61aj5kv/1/

bryanlittlefield avatar Mar 03 '15 19:03 bryanlittlefield

onInvalid is called for each invalid field with the this context set to the field. You don't have to iterate through the errors to figure out which error occurred.

Checking against this is the easiest way to figure out which field was invalid.

You can do something like:

onInvalid: function() {
   // some special field
  if($(this).hasClass('special') {
    $('.some.modal').modal('show');
  }
}

jlukic avatar Mar 06 '15 17:03 jlukic

Brilliant, thank you!

bryanlittlefield avatar Mar 09 '15 16:03 bryanlittlefield