D7 Natively support the HTML5 required and aria-required FAPI properties

Created on 6 July 2018, over 6 years ago
Updated 30 January 2024, 10 months ago

Problem/Motivation

HTML5 offers a "required" form element attribute for browser-native client-side validation.

Proposed resolution

Using the #required Form API attribute, add either of the following to an element:

TRUE: required="required" aria-required="true"
FALSE: [nothing]

For buttons that shouldn't require validation (like a 'Previous' button on a multi-paged form), a 'formnovalidate' attribute can be added to its #attributes property, which would output like this:

TRUE: formnovalidate="formnovalidate"
FALSE: [nothing]

Remaining tasks

Commit the patch from #1174938-93: Natively support the HTML5 required and aria-required FAPI properties (attached)

User interface changes

HTML5 browsers will validate form elements that are marked as required, giving the user feedback on empty fields as they submit the form.

API changes

This patch adds the following options to the Form API:

$form['myelement']['#attributes']['required'] = TRUE;
$form['mysubmitbutton']['#attributes']['formnovalidate'] = TRUE;

Original report by Dave Reid

Currently adding a #required => TRUE to a form element gives it a class, but now with HTML5 we can put the 'required' as a direct attribute in the form element itself.

http://diveintohtml5.info/forms.html#required

--
We're going to need a follow up issues for a required/toolbar bug.

Feature request
Status

Needs review

Version

7.0 ⚰️

Component
Form 

Last updated 3 days ago

Created by

🇨🇦Canada joseph.olstad

Live updates comments and jobs are added and updated live.
  • Accessibility

    It affects the ability of people with disabilities or special needs (such as blindness or color-blindness) to use Drupal.

  • Regression

    It restores functionality that was present in earlier versions.

  • Needs accessibility review

    Used to alert the accessibility topic maintainer(s) that an issue significantly affects (or has the potential to affect) the accessibility of Drupal, and their signoff is needed (see the governance policy draft for more information). Useful links: Drupal's accessibility standards, the Drupal Core accessibility gate.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024