Hi,

So following up from this issue ticket: https://www.drupal.org/project/webform/issues/2980671, I've discovered an issue where the numerical condition didn't work as it should be.

Here's some case:

Configuration setup:

  • Setup a Number field called "Test number".
  • Setup a Textfield field called "A textfield", and set the Conditional as follow:
    • State: Visible
    • Element: "Test number"
    • Trigger/Value: Greater than 500 (NOTE: the same config can also use for 'Less than 500')

Scenario:

  • User type in 501, field "A Textfield" showing up --> This is correct
  • User type in 60, field "A Textfield" showing up --> This is NOT correct

NOTE: the same scenario can also be use for 'Less than 500'

Here are a screencast and source for reference:
Screencast: http://www.giphy.com/gifs/1k0ZdyLV0dAzWH47I6
Source:

test_number:
  '#type': number
  '#title': 'Test number'
  '#min': '1'
  '#max': '10000'
show_up_when_greater_than_500:
  '#type': textfield
  '#title': 'Show up when greater than 500'
  '#states':
    visible:
      ':input[name="test_number"]':
        value:
          greater: '500'
show_up_when_less_than_500:
  '#type': textfield
  '#title': 'Show up when less than 500'
  '#states':
    visible:
      ':input[name="test_number"]':
        value:
          less: '500'

Problem:
Turns out the values that returned is in a form of String which causing unexpected behavior. It should be returning Integer instead.
Thus, attached is the patch for the fix.

Kindly review this as appropriate, thanks!

Regards,
Ardi

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ardnet created an issue. See original summary.

ardnet’s picture

Issue summary: View changes
jrockowitz’s picture

I think we should use parseFloat to support decimal values.

jrockowitz’s picture

Status: Active » Needs review
FileSize
667 bytes
jrockowitz’s picture

This patch also applies floatval() to the server-side conditions.

Status: Needs review » Needs work

The last submitted patch, 5: 2981338-5.patch, failed testing. View results

jrockowitz’s picture

Status: Needs work » Needs review
FileSize
1.44 KB

The last submitted patch, 4: 2981338-4.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 7: 2981338-6.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jrockowitz’s picture

Status: Needs work » Needs review
FileSize
1.44 KB

  • jrockowitz committed ef8e7fc on 8.x-5.x
    Issue #2981338 by jrockowitz, ardnet: Conditional fields using Number...
jrockowitz’s picture

Status: Needs review » Fixed

I committed that patch. Thanks

ardnet’s picture

Nice! thx for the patch improvement :)
It's working well.

Cheers!

Status: Fixed » Closed (fixed)

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