Adding the required state to radios, adds the required marker to all available options.
$form['field_options']['#states']['required'] = array(
':input[name="field_required[und]"]' => array('value' => 1)
);



| Comment | File | Size | Author |
|---|---|---|---|
| #72 | 2731991-72.patch | 1.84 KB | dunot |
| #70 | 2731991-64.patch | 2.88 KB | andresgmh |
| #69 | Screen Shot 2023-02-01 at 11.54.16 am.png | 4.01 KB | pameeela |
| #63 | interdiff_61-63.txt | 2.58 KB | vsujeetkumar |
| #63 | 2731991-63.patch | 2.77 KB | vsujeetkumar |
Comments
Comment #2
r-mo commentedComment #3
r-mo commentedComment #4
r-mo commentedComment #5
surbz commentedPatch applies clean, Screen shots attached.
Comment #6
surbz commentedComment #7
fabianx commentedI am very pretty sure this needs to be fixed in D8 first. And there it can also be tested.
Comment #8
aerozeppelin commentedJust wondering, is this the fix for D8 ? https://www.drupal.org/node/1239930#comment-10371121
Comment #9
fabianx commentedIt looks different to me, can someone verify if this exists in D8 or not?
Comment #11
robpowell@fabianx
I confirmed that this is still an issue on 8.1.8
I added three fields to basic page content type:
Here is my form_alter hook:
Comment #12
fabianx commentedThanks for checking, we need to fix this in D8 first and it needs some tests.
Comment #13
robpowellI was looking at the previous patch which only updates states.js. The best I can tell, it adds the styles ( red asterisk )...
In my above example I compared radio with text field. For radio fields, I found the following differences, e.target was a fieldset and the e.target.id includes '--wrapper'. For text fields, the e.target is the input and and the id matches the input. One more thing of note, the e.target.id is used to populate the label variable and in turn the find function. This will not return any results for radio fields. I quickly reviewed that this is working for checkboxes (checkboxes become required), the only difference I could determine off the bat was that checkboxes were in a div and not a fieldset.
Other than the js changes, is there any other work that needs to be completed for this? Possibly the new form fields added to validation? I am still new to Drupal but would love to help get this change in. If you could let me know the ETA on any patches and how I could assist, that would be appreciated.
Comment #14
nod_Comment #15
robpowellAlright, my patch isn't going to win any awards but it does what I need it to do and hopefully shines some light on some of the issues.
Edit: add an image
Comment #16
robpowellComment #17
jrockowitz commentedThe patch did not work for me in Drupal 8.2.x. I could not immediately 'grok' the patch to know why it did not work.
Below is the temporary CSS work-around that I am using in Webform 8.x-5.x
Comment #20
andypostComment #21
andypostComment #22
arunkumarkThe patch has been re-rolled for Drupal 8.5.x version.
Comment #24
GrandmaGlassesRopeMan@arunkumark - Your patch is missing the changes to the ES6 files. See this change record for more information.
- This patch fixes the coding standards errors present in #22
- Includes the changes ported to the
.es6.jsfile.Comment #25
r.nabiullin commentedRerolled #24 because patch is not applied on D 8.4.3, do not commit this to 8.5.x
Comment #27
r.nabiullin commentedComment #28
GrandmaGlassesRopeMan@nabiyllin Have a look at https://www.drupal.org/core/backport-policy. This change could get committed to
8.5.xand then possibly cherry-picked backwards.- This is just a reupload of #24.
Comment #29
r.nabiullin commented@drpal it's after patch merging, but I need in this patch now on project which work on 8.4.
I'm sure I'm not the only one who need this.
Comment #31
andypostOnly tests left here
Comment #33
andypostProbably because of https://www.drupal.org/node/2986680
Comment #34
gaydabura commentedre-rolled
Comment #35
savkaviktor16@gmail.com commentedComment #36
volkswagenchicktagging for badcamp 2018
Comment #38
ilya.no commentedMeanwhile attaching patch for current core version with update for latest fix in states.es6.js and states.js files.
Comment #39
GrandmaGlassesRopeManComment #40
volkswagenchickTagging for DrupalNorth 2019
Comment #41
volkswagenchickTagging for DrupalCamp Colorado 2019 (Sunday August 4)
Comment #42
audacus commentedI use a slightly modified version of #38 for core 8.7.3 with webform 5.0-beta12.
Instead of setting the required classes onto the
legendelement I have to set the required classes onto thelegend .fieldset-legendspan element.Comment #43
jrockowitz commented#2951317: Radios element missing "required" attribute is a related issue and is the CSS work-around from#17.
Comment #45
volkswagenchickTagging for SFDUG Global contrib weekend event (Thursday Jan 23)
Comment #47
piggito commentedRe-rolled for 9.1.x
Comment #48
himanshu_sindhwani commentedThe patch mentioned in #47 doesn't seem to work for me. I created two fields namely test and test condition. I added code to make test condition required when test has value = 'one' using form alter. What I observe before applying the patch is the div wrapper of the test condition radio button gets an attribute of required when the value of test = 'one' and the same is happening after I apply the patch.
Here is the screenshot which will make it more clear, what I did :
You can clearly see the required attribute on div which is completely useless. It should have been on one of the input fields of radio button.
Comment #49
himanshu_sindhwani commentedComment #50
himanshu_sindhwani commentedHere, I have created a patch to fix the issue faced in #48. This patch will add the required attribute on the input tag instead of the div tag. How ever the tags like texarea are not handled. For them to be required we have add a custom validation on form submit as implemented in body field when you make it required.
Comment #51
himanshu_sindhwani commentedComment #52
priyanka.sahni commentedComment #53
priyanka.sahni commentedComment #54
sharma.amitt16 commentedAfter applying patch #50, it works for me.
Check the below screenshot, it is working as expected.
Alter hook look like below
Looks good to me for RTBC.
Comment #55
batkorThank guys!
Patch #42 worked for my.
Drupal 8.8.5.
Patch #50 not apply
Comment #57
quietone commentedI thought I would test this but the Issue Summary does not include steps to reproduce. :-( I went ahead and added select list fields to the article content type on a fresh install of 9.2.x and using that I was not able to reproduce the problem.
The issue summary only describes the problem. tagging for issue summary update. For help with that there are Issue Summary Template examples available.
Comment #58
clairedesbois@gmail.comPatch #42 works for me in Drupal 8.9.13
Comment #60
viniciusrp commentedPatch #50 works for me in Drupal 9.2.x
Comment #61
vsujeetkumar commentedRe-roll patch created for 9.3.x.
Comment #62
vsujeetkumar commentedFixed "Custom command fail" issue. Please have a look.
Comment #63
vsujeetkumar commentedPlease ignore my previous(#62) patch, Fixed custom command fail issue.
Comment #67
smustgrave commentedMoving to PNMI as the summary needs an update. I tried replicating locally but was not able to. The required seems to just go to the label which is desired.
Comment #69
pameeela commentedDefinitely does not occur now, in Claro or Seven:

Comment #70
andresgmh commentedRe-rolling to 9.5.7 version
Comment #71
sanderjp commentedI would not recommend using this patch. The changes to
core/misc/states.jsare breaking form states on textfields and textareas, you cannot make those fields required anymore. Took me way too long to figure that out.Comment #72
dunot commentedFor D10.2.6 term ref field.