Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

novalidate

Turns off the browser's submit-time validation for a whole form (novalidate) or for one submit button (formnovalidate). Constraints still apply; only the blocking and the bubbles stop.

Overview

novalidate on a <form> tells the browser not to check constraints when the form is submitted: no blocking, no validation bubbles, no focus jump. formnovalidate does the same for submissions started by one particular button, which is how a "Save draft" button gets past empty required fields.

The constraints themselves keep working. validity, checkValidity(), :invalid and :user-invalid all behave as before; only the submit-time check is skipped.

Applies to: novalidate on <form>. formnovalidate on <button> (submit type), <input type="submit"> and <input type="image">.

Values

Both are boolean attributes: present means "skip", absent means "validate". novalidate="false" still skips. The DOM properties are form.noValidate and button.formNoValidate (capital V).

AttributeOnEffect
novalidate<form>No submission from this form is checked.
formnovalidatesubmit buttonSubmissions started by this button are not checked. Other buttons still validate.
Neither—The browser checks every constraint on submit (the default).

Examples

Custom error UI: let data-validate set it

The usual reason to add novalidate is to replace the browser bubbles with inline messages. In Vanilla Breeze you don't write that code: add data-validate to the form. The form coordinator sets novalidate from JavaScript, so without JavaScript the browser still validates, and with it each field shows its message in output.error.

A larger example with an error summary: form validation, progressive enhancement layers.

Validating by hand

Without the coordinator, set noValidate from script (not in the markup, so no-JS users keep native validation) and use the constraint API yourself.

In Vanilla Breeze

  • form[data-validate] adds novalidate when it enhances the form (src/lib/form-coordinator.js) and runs its own checks on submit: every <form-field>, data-match pairs and data-min-checked / data-max-checked fieldsets. Messages come from data-message-* attributes.
  • formnovalidate and data-validate. A submission started by a formnovalidate button skips the coordinator's checks, as it would natively, in every submit mode (native, data-submit="fetch" and "event"). An open error summary is hidden; marks already on fields stay until they are fixed. vb:beforesubmit still fires.
  • Wizard. A data-wizard form skips its "go to the step with the first error" routing when the form has novalidate in its markup or the submit button has formnovalidate (src/lib/wizard.js). The novalidate that data-validate adds does not count: a wizard with data-validate still routes.
  • Styling still applies. novalidate does not stop :user-invalid from matching, so VB's error border (src/native-elements/input/styles.css) and form-field's error reveal still appear after the user edits a field.

Accessibility

  • If you suppress native validation, your replacement must be at least as accessible: an error next to the field, linked with aria-describedby, aria-invalid="true" on the control, and focus moved to the first error or an error summary. <form-field> and data-validate do all of that.
  • A Save-draft button should say what it does. Users who press it with errors on the page need to know the data was saved but not published.

Gotchas

  • novalidate does not stop the browser from enforcing maxlength while typing, or a number field from rejecting letters (those are input rules, not submit checks).
  • Skipped validation is not server validation. The server must check everything again.
  • form.submit() never validates and never fires submit, with or without novalidate. Use form.requestSubmit(button) to submit as if the user pressed that button.
  • Putting novalidate in the HTML of a form that relies on script for its messages leaves no-JS users with no validation at all.

Related

Which to choose

  • data-validate — custom, accessible error messages. It sets novalidate for you.
  • formnovalidate — one button must get past incomplete data (drafts, "Cancel" that posts). Works in plain and data-validate forms.
  • novalidate in markup — rarely: only when the server is the sole validator and you want no client checks at all.
↑