An HTML5 event raised before validating input fields.

Is there any event that occurred before checking the fields in the HTML5 form and before submitting this form?

AFAIK, a submit event is generated just before the form is submitted, but after the validation step, so it's too late for me.

Refresh . I have a text box with the required property, and if the user has JS, I want to replace it with an HTML editor. The HTML editor synchronizes its contents from textarea to submit (after the verification step), so the text area is always empty for the browser. That is why I ask for a validated event. Any other answer that solves this problem will be accepted.

+4
source share
1 answer

No, there is no event that fires before verification. There is only an invalid event that fires after checking an invalid field, but until the validation user interface is displayed (prevention by default prevents the browser validation interface from being displayed).

If you want to synchronize two fields, you need to use two events. The first is DOMContentReady , and the second is the change event.

Additional information: if you hide an invalid field element, the browser cannot show the verification message to the government. You can get around this with the following code (note that it is assumed that you are using jQuery 1.6x and a special structure):

 $('textarea.wysiwyg').bind('invalid', function(e){ //remove validation bubble e.preventDefault(); //implement your own validation UI $(this).next('div.wysiwyg').after('<p class="error">'+ $.prop(this, 'validationMessage') +'</p>'); }); 
+8
source

All Articles