- ππΊHungary nevergone NyΓregyhΓ‘za, Hungary, Europe
Contrib blocker, see: π Settings form refactoring Active
- Status changed to Needs work
almost 2 years ago 12:08am 17 March 2023 - πΊπΈUnited States dww
Here's a much simpler failing test than what's described in the summary. π
It's basically just this:
$form['checkbox_trigger'] = [ '#type' => 'checkbox', '#title' => 'Checkbox trigger', ]; $form['radios_required_when_checkbox_trigger_checked'] = [ '#type' => 'radios', '#title' => 'Radios required when checkbox trigger checked', '#options' => [ 'value1' => 'Value 1', 'value2' => 'Value 2', ], '#states' => [ 'required' => [ ':input[name="checkbox_trigger"]' => ['checked' => TRUE], ], ], ];
- π³πΏNew Zealand quietone
@Spokje, yes, that is wrong. π Radios element missing "required" attribute Needs work .
This also needs a better title, one that explains what is being fixed.
- πΊπΈUnited States dww
Hrm, looking more closely, that test isn't exactly right, either. There's weirdness with what element we're selecting when it comes to 'radios'. Are we targetting the fieldset, or the input, or...? But, it's a start. π The form changes are fine. We probably just need to be more specific with how we select which elements we're manipulating in the test itself.
And yeah, in light of π Radios element missing "required" attribute Needs work , we may want/need to change which elements are getting the required attribute, anyway.
- π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
What happens in this scenario:
* user checks box to make radio required
* user selects a radio
* user unselects checkbox to make radio visibleIn that scenario the radio option selected in step 2 would still be sent, there's no way to unset a radio in a set of radios once set.
- π¨π¦Canada gapple
This may be because of π Form radios/checkboxes elements should have js-form-wrapper class Postponed: needs info ?
- ππΊHungary nevergone NyΓregyhΓ‘za, Hungary, Europe
How can the resolution of this proceed?
- ππΊHungary nevergone NyΓregyhΓ‘za, Hungary, Europe
How could this be fixed?
- πΊπΈUnited States bkline Virginia
@larowlan (#15) Sorry for the delayed response. Yes, I believe it's true that Drupal provides no way to prevent the return of values entered/selected on one path when the user changes his/her mind and selects another path (a mythical #forbidden mirror image of #required), and it's also true that (short of reloading the form and starting over) the user can't back out of having a selection for a set of radio buttons once a selection has been made. But that just means that the submit handler just has to be intelligent about what it needs, based on the state of the field which determines which path was taken by the user when the form was submitted. In other words, it's not a big deal that the handler might get more than it needs, but it is a problem that it might get fewer values than are needed (and that the rendering of the form fails to convey the fact that the field is required).