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.

Comments

Alexander Schlabach created an issue. See original summary.

dww’s picture

Ugh, 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.

dww’s picture

Status: Active » Needs review
Issue tags: -Needs tests
Related issues: +#2419131: [PP-1] #states attribute does not work on #type datetime
StatusFileSize
new4.66 KB
new5.22 KB

Initial 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.

The last submitted patch, 3: 3133532-3.test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

dww’s picture

StatusFileSize
new5.3 KB

Adds the missing docblock on the new test form class.

dww’s picture

Title: States not working properly » JavaScript #states not working on 'duration' form elements
dww’s picture

StatusFileSize
new6.4 KB
new2.52 KB

My 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.

  • dww committed c4b4b82 on 8.x-2.x
    Issue #3133532 by dww, Alexander Schlabach: JavaScript #states not...
dww’s picture

Version: 8.x-2.0-rc3 » 8.x-2.x-dev
Status: Needs review » Fixed

Seeing no objections, committed #7 and pushed to 8.x-2.x branch.

When we'll ship 8.x-2.0-rc4 is still TBD.

  • dww committed 05692e8 on 8.x-2.x
    Issue #3133532 by dww: Follow-up fixes to duration_field_form_test.info....
Alexander Schlabach’s picture

Awesome - thanks for getting a patch and an update pushed!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.