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.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3418485-add-required-attribute.patch | 845 bytes | matio89 |
Issue fork phone_international-3418485
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
Comment #3
matio89 commentedAttached the patch as well.
Comment #4
matio89 commentedComment #5
c_archer commentedThis worked for me and solved my issue of shipping prices not been calculated. Patch works well.
Comment #7
saidatom