The #states do not currently get added to the rendered element properly. Chasing down the problem reveals a bug in ProcessStatesTrait.php, line 30. The $element variable is passed, but should possibly be passed by reference since the function doesn't return the element.
This can either be resolved by passing it by reference OR by returning $element.
I edited the function to pass the variable by reference and that is working properly for me now.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 3133532-7.patch | 6.4 KB | dww |
Comments
Comment #2
dwwUgh, so sorry! I broke this with #3093354: Don't use deprecated drupal_process_states() if FormHelper::processStates() exists. I should have known better, since I wrote code in datetime_extras that uses #states on a duration_field!
Here's the fix in patch form.
We should probably add some JS tests to make sure we don't break this again. :( Hate to ship rc4 so soon after rc3. Not sure this is major enough to matter, but it's an annoying regression.
Comment #3
dwwInitial test coverage. So far, it's only testing 'invisible'.
I think we have deeper problems using #states for 'required', since we'd need to check for all the actual number elements inside the wrapper. Related to #2419131: [PP-1] #states attribute does not work on #type datetime. Even with the fix applied, if I expand the test to check for 'required' via #states, it still fails. I don't care much, since toggling #required via #states is mostly pointless (since it doesn't change form validation, just). Haven't looked into every possible #states feature, either. But visibility seems to be the main use case, so let's start here.
Comment #5
dwwAdds the missing docblock on the new test form class.
Comment #6
dwwComment #7
dwwMy head's been all up in JS tests for #states thanks to #2702233: [backport] Add JavaScript tests for Form API #states: required, visible, invisible, expanded, checked, unchecked. A few more improvements here. In addition to checking visibility just on the container, let's also find and verify the visibility of the label and some of the actual number fields that are sub elements.
Comment #9
dwwSeeing no objections, committed #7 and pushed to 8.x-2.x branch.
When we'll ship 8.x-2.0-rc4 is still TBD.
Comment #11
Alexander Schlabach commentedAwesome - thanks for getting a patch and an update pushed!