During altering a form I realized that form '#states' are currently not working with managed file fields.
To reproduce:
1. Create a new custom form
2. Add two fields
2.1. Image field
2.2. Boolean field
3. Configure the form state for the image field that it should just be shown when the boolean field value is TRUE.
It works for every other field type except this one.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | CORE-managed_files_field_states-2705471-6.patch | 603 bytes | Anonymous (not verified) |
Comments
Comment #2
jrockowitz commentedI can confirm that this is an issue.
It is due to the #attributes being reset via template_preprocess_file_managed_file().
As soon as
$variables['attributes'] = array();is removedtemplate_preprocess_file_managed_file()the #states API starts working as expected.Comment #4
deltahex commentedThe same problem exists for the "datetime" form field as well. The template_preprocess function is identical but the above solution is not applicable in this case. I will spend some time on it and will provide an update here.
Also there is a duplicated "id" attribute for the element wrapper div and the file input element itself.
Comment #5
wheelercreek commentedI don't know if this is related, but when using filefields on a wizard page (multi-page) YAML form, I'm suddenly getting these warnings about array expected..
Comment #6
Anonymous (not verified) commentedIndeed, the
drupal_process_states()uses thedata-drupal-statesattribute to pass JSON encoded data to theDrupal.behaviors.states.Comment #7
Anonymous (not verified) commentedComment #10
idebr commentedHello everyone,
This issue was also reported at #2847425: #states not affecting visibility/requirement of managed_file. The related issue has a patch and contains an automated test to prevent this bug from occurring in the future.
I'll close this issue as a duplicate, so we can focus our efforts in the related issue.