Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have a Phone Number field, phone_1, and a Phone Number Type radio selection (Home, Cell, Work), phone_1_type. The phone_1_type should be required if phone_1 is filled, but the current code is making the fieldset that contains phone_1_type buttons required, and is allowing submission of the form without ever selecting a radio option.
Example YAML
phone_1_container:
'#type': flexbox
phone_1:
'#type': tel
'#title': 'Phone 1'
'#description': 'Just enter the 10 digits of your number without spaces or dashes.'
'#title_display': inline
'#description_display': tooltip
'#maxlength': '10'
'#required': true
'#pattern': '[0-9]{10}'
phone_1_type:
'#type': radios
'#title': 'Phone 1 Type'
'#title_display': invisible
'#options':
home: Home
cell: Cell
work: Work
'#options_display': side_by_side
'#states':
required:
':input[name="phone_1"]':
filled: true
Screenshot of HTML after filling in phone_1
Comment | File | Size | Author |
---|---|---|---|
Screen Shot 2017-02-27 at 9.00.44 AM.png | 281.49 KB | frogdog_tech |
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThis is an issue with how Drupal core has implemented radios and checkboxes.
@see #994360: #states cannot check/uncheck checkboxes elements and #2836364: Wrapper attributes are not supported by composite elements, this includes radios, checkboxes, and buttons.
This is such a common element setup, I am tempted to create a new composite element called 'Telephone with type' (webform_phone).
Comment #3
ptsimard CreditAttribution: ptsimard commentedI'm actually in the process of researching through your code how to create composite elements.
Due to some requirements for a project I need a multiple values composite phone element that have 4 fields such as:
A similar thing will also be needed for :
So while my requirement is more specific and will require bespoke composite fields, I just wanted to add a "Me too" on the "Telephone with type" idea.
Comment #4
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@ptsimard I think this element is going to happen.
One major limitation is that composite elements do not support nested composite elements or nested multiple values.
For example, the contact composite can not include the telephone composite.
Comment #5
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedPlease test the patch in #2856795: If radio buttons are required but not filled form is nevertheless submitted which also fixes this issue.
I have to give credit to @johnnny83 for inspiring the JavaScript workaround.
Comment #6
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI committed the patch. Please download and review the latest dev release.