I'm using html5's required attribute on input-elements in a form. Normally when you use them and submit the form you get a message which element(s) are invalid.
I'm in a special situation which requires me to test the state of the input fields before posting. (If they are all ok, then someone elses code (another plugin in Wordpress) is fired by use of simulating a click on another submit element.)
Here's a snippet of relevant jQuery-code:
var t = $(this);
found_required = false;
$("input").each(function() {
if ( $(this).hasClass('required') ) {
if ($(this).is(":invalid")) {
t.removeClass('swishmode');
//Tell user this element is required
found_required = true;
}
}
});
if ( found_required == true ) {
$('form.give-form').attr('action','Javascript:void();'); //Just an attempt
$(this).click(); //Just an attempt
return; //Returns user back to form without doing different things below
}
//Code to do different things...
My question is - is there a way to show default error like it would be shown when submitting a form with invalid data? (or do you have to write custom error handling for this purpose)
The actual code works as I have it right now, but the user gets no indication that what fields are incorrect. I know I could just put some style of those input elements and I will do so if this above is not possible.