Javascript For Html5 Required Field Set Up To Work In Safari
I am using the following script to change the HTML5 required attribute of my input elements. I am wonder whether there is a way to modify this script to make it also work in Safari
Solution 1:
You can also do this:
var valid = true;
$('input[required]').each(function() {
if (this.value == '') {
// Alert or message to let them know
valid = false;
returnfalse; // stop on first error, or remove this and it'll go through all of them.
}
});
if (valid === false) {
returnfalse;
}
Solution 2:
Check out this page here. It contains a hacky solution that should add the desired functionality
http://www.html5rocks.com/en/tutorials/forms/constraintvalidation/#toc-safari
Solution 3:
You're going to need to run the check yourself using an event handler on your form submission. In that handler, you run the check yourself, and if it fails, you display whatever error message and block the submission using preventDefault
or return false
.
An example can be found here, though as it notes, you need to be careful if you use checkValidity as your means of checking the form.
Post a Comment for "Javascript For Html5 Required Field Set Up To Work In Safari"