New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DX] Form API: Adding #attributes
to fields of type container
breaks #states
#5157
Comments
container
do not support #attributes
#attributes
to fields of type container
breaks #states
Simple PR up for review: backdrop/backdrop#3689 ...makes sure that any Should be easy to test this on your local:
Thanks |
Thank you @indigoxela for pointing the obvious in the PR 😉 I've pushed another change, which makes sure that #711 does not regress. To test it, add these form elements to your form: $form['toggle'] = array(
'#type' => 'radios',
'#title' => t('Toggle me'),
'#options' => array('hide' => 'hide', 'show' => 'show'),
'#default_value' => 'hide',
);
$form['option'] = array(
'#type' => 'checkboxes',
'#title' => t('Options (should not be shown if options hidden)'),
'#options' => array('one', 'two', 'three'),
'#attributes' => array('class' => array('some', 'classes')),
'#description' => t('Some description (should not be shown if options hidden).'),
'#states' => array(
'visible' => array(
':input[name="toggle"]' => array('value' => 'show'),
),
),
); Then play with the "Toggle me" radios, and confirm that when the checkboxes are hidden, the respective label and help text are also hidden with them. (as a bonus, also confirm that the |
Works for me. Tested as you described and also with the latest version of Conditional Fields, which has a bit of an awkward workaround required currently (conditional fields need to be put inside of a field group) but which works as expected without any extraneous field group using this PR. 👍 |
Thanks for testing @laryn 🙏🏼 ...now I need to fix those 100s of failing tests + plus adjust the inline comments and the description in the docblock of the |
I added the change record for that old issue (and removed it's label) https://docs.backdropcms.org/change-records/functions-theme_radios-and-theme_checkboxes-have-been-removed |
@klonos The failing tests are the only issue on this one, is that right? |
@laryn I think so, yes. I'll rebase, in order to get GHA tests, and will work to finalize this. |
Sorry for taking this long. This is finally done! 🎉 |
I have tested again in the sandbox using the Conditional Fields module as described earlier, and it functions as expected. Also confirmed that all the checks are green! 👍 |
this looks like it fixes #3489 as well, nice. PR looks good to me. |
Thanks @bradbulger and @laryn for the reviews! And @jenlampton for making that change record! I've merged @klonos's backdrop/backdrop#3689 into 1.x and 1.20.x. |
This is a sibling issue to #3817...
It is a known issue that
'#markup'
form elements do not support#states
. So this won't work:The workaround is to add a
'#type' => 'container'
around them, and use#states
on the container form element instead of directly on the markup element.This works fine:
This issue here is not about solving that problem...
Everything works as expected with the above-mentioned workaround, until you try adding any class to the container form element (via
#attributes
).This does NOT work:
To make it work again, one needs to manually add the
form-wrapper
class to the container element:The text was updated successfully, but these errors were encountered: