Native js encapsulated form submission verification method

the native checkValidity () method returns a Boolean value. True indicates that the check is passed, and false indicates that the check is not passed. Therefore, the submit form can be encapsulated as the following function.

function submitForm (action) {
var form = document.getElementById ("form");
form.action = action;
if (form.checkValidity ()) {

)
form.submit();

}
}

but this checkValidity () method only validates some of the basic checks provided by the browser api. Now you need to customize some checks (for example, verify that the form A value must be greater than the form B value. And whether a form value in the background of the ajax request is verified repeatedly. How to improve the method to make it a general method.

Aug.18,2021
It is impossible for a native method of

to consider the contents of its superset. You can consider overriding overwrite in form.prototype, or write one yourself.

Menu