Problem/Motivation

Currently, the PhoneInternationalElement custom form element does not support the addition of the required HTML attribute when the element is set as required. This is problematic for forms that need to enforce the completion of the phone number field, as there's no HTML5 validation for required fields.

Steps to reproduce

Create a form using the PhoneInternationalElement.
Set the #required attribute to TRUE on this element.
Render the form and inspect the HTML output.
Notice the absence of the required attribute in the rendered HTML.

Proposed resolution

Enhance the processInternationalPhone method within the PhoneInternationalElement class to conditionally add the required attribute to the element's attributes array based on the #required property.

User interface changes

This change will add the required attribute to the HTML output of the phone field when necessary, which may trigger HTML5 validation UI elements in browsers.

CommentFileSizeAuthor
#3 3418485-add-required-attribute.patch845 bytesmatio89
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

matio89 created an issue. See original summary.

matio89’s picture

StatusFileSize
new845 bytes

Attached the patch as well.

matio89’s picture

Status: Active » Needs review
c_archer’s picture

Status: Needs review » Reviewed & tested by the community

This worked for me and solved my issue of shipping prices not been calculated. Patch works well.

saidatom made their first commit to this issue’s fork.

saidatom’s picture

Assigned: matio89 » Unassigned
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.