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
Comment | File | Size | Author |
---|---|---|---|
#10 | 2981338-10.patch | 1.44 KB | jrockowitz |
| |||
#7 | 2981338-6.patch | 1.44 KB | jrockowitz |
#5 | 2981338-5.patch | 1.44 KB | jrockowitz |
#4 | 2981338-4.patch | 667 bytes | jrockowitz |
cond-fields-gtlt-issue.patch | 659 bytes | ardnet | |
Comments
Comment #2
ardnet CreditAttribution: ardnet commentedComment #3
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI think we should use parseFloat to support decimal values.
Comment #4
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #5
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThis patch also applies floatval() to the server-side conditions.
Comment #7
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #10
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #12
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI committed that patch. Thanks
Comment #13
ardnet CreditAttribution: ardnet commentedNice! thx for the patch improvement :)
It's working well.
Cheers!