HTML and CSS Reference
In-Depth Information
If you run the order form example in Safari 5.1 or older versions of other browsers (such
as IE9), you'll notice that the validation functionality doesn't work—the form will submit
without performing any validation. In this section, you'll learn how to use JavaScript to
perform this validation and, if any errors are found, prevent submission of the form.
Step 2: Build fallback constraint validation for Safari 5.1
In the case of Safari 5.1, the Constraint Validation API is partially supported. This means if
you have an <input> element in your form with the required attribute set, the element
wouldn't pass validation in Safari 5.1. But Safari doesn't implement any of the UI features,
such as displaying error messages next to invalid fields, nor does it prevent the form from
submitting if errors exist in the form. Let's start off by reversing this and displaying an er-
ror message to the user if there are errors. Add the code from the following listing to your
app.js file, right after the code from the previous listing.
Listing 2.14. app.js—Preventing an invalid form from submitting in Safari 5.1
Search WWH ::

Custom Search