Event in HTML5 form raised before validation of input fields.

前端 未结 1 461
生来不讨喜
生来不讨喜 2021-01-19 02:43

Is there any event raised before the validation of fields in an HTML5 form and before the submit of this form?

AFAIK, the submit event is raised just before the subm

1条回答
  •  生来不讨喜
    2021-01-19 03:22

    No, there is no event which fires before validation happens. There is only the invalid event, which is fired after validation of an invalid field, but before the validation UI is shown (preventing the default prevents showing the browser validation UI).

    In case you want to sync two fields, you have to use two events. The first is DOMContentReady and the second is the change event.

    Additional info: if you hide the invalid field element, the browser can not show the validation message to the user. You can workaround this with the following code (note this assumes 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('

    '+ $.prop(this, 'validationMessage') +'

    '); });

    0 讨论(0)
提交回复
热议问题