This patch adds some additional information to the #states example in the Form API Example module that helps make it easier to figure out how to construct the array value for the #states parameter. And where to look to find more information about possible valid values for both the states and conditions.

It also includes a fix in the existing docblock for the class changing #state to #states since #states is the property name. And updates the existing jQuery selector used to :input[name="needs_accommodation"] which is more generic, and probably a better best-practice to document than input[name="needs_accommodation"].

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eojthebrave created an issue. See original summary.

navneet0693’s picture

Status: Needs review » Reviewed & tested by the community
Mile23’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs tests
FileSize
2.32 KB
2.13 KB

I made some minor edits, in this patch.

+++ b/form_api_example/src/Form/StateDemo.php
@@ -43,9 +43,21 @@ class StateDemo extends DemoBase {
-          'input[name="needs_accommodation"]' => ['checked' => FALSE],
...
+          ':input[name="needs_accommodation"]' => ['checked' => FALSE],

Since this patch changes the selector, and since there's no test of whether this works in the first place, we need to add a test that proves that this selector works, and therefore the change isn't breaking anything.

So that's a functional JS test that gets the page, verifies that the field is invisible, checks the checkbox, and then verifies that the field is visible.

Setting to NR to run the patch through the testbot, but really this is NW.

Mile23’s picture

Status: Needs review » Needs work
eojthebrave’s picture

Status: Needs work » Needs review
FileSize
3.81 KB

Here's an updated patch with tests. This contains the patch from #3 + a new file with tests.

  • Mile23 committed c635d82 on 8.x-1.x authored by eojthebrave
    Issue #2933259 by eojthebrave: Add some additional information to...
Mile23’s picture

Status: Needs review » Fixed

Diggit. Thanks!

Status: Fixed » Closed (fixed)

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