Problem/Motivation
When we set the Value input mode with any of the Set of values (All there values(AND), Any of these values (OR), Only one of these values (XOR) or None of these values (NOT)) with the value 0, it is not working, and is being treated as null.
Steps to reproduce
Create a conditional field for any field
Values input mode: anything under "Set of values"
Set of values: 0
It will work if the field controlled by is a number field, but is not going to work if it is controlled by any field as a select list or radio widget.
Proposed resolution
Change where the validation of the field is with the method empty (this php method treats 0 as being empty) to test the variable with the "0" value.
Remaining tasks
Review the patch
Comments
Comment #2
hmendes commentedAddding the patch, please review.
Comment #3
chucksimply commented#2 didn't fix the issue on my setup.
Comment #4
hmendes commentedAdding a new patch.
There's still having with the Value input mode with any of the Set of values, but this issue I'm going to solve specifically the problem addressing the "0" value not being saved.
The problem that's still happening is addressed by #3109227: Conditional Fields not showing for multiple value select fields on node edit form with option 'Any of these values (OR)...' (but not only with the OR condition) and #1149078: States API doesn't work with multiple select fields
Comment #5
jessicacs commentedRe-roll of the patch #4.
Comment #6
takuma shimabukuro commentedComment #7
takuma shimabukuro commentedI reviewed the patch, so it's enough to validate 0.
moving status for RTBC
Comment #8
colanBecause we're duplicating this code in a few places, which is a terrible idea, let's move it to a method like
notEmpty(), and then call it from each location.Comment #9
andregp commented@colan I'll take a look at this
Comment #10
andregp commentedI ran a search with the regex
!empty\([\s\S]*\) \|\| [\s\S]* == "0"to check how many times the code!empty($options['values']) || $options['values'] == "0"or similar appeared on the module files. It appears three times, once insrc/ConditionalFieldsFormHelper.phpand twice insrc/Form/ConditionalFieldEditForm.php. Because it only appears more than once insideConditionalFieldEditForm.phpI created the new function there and leftConditionalFieldsFormHelper.phpuntouched.But if the intention was to replace all three instances with the notEmpty function then a Trait may be a better approach. (So I created a second patch using a trait, just in case).
Comment #11
elberComment #12
elberHi I revised and applied the patch #17 and when we set the value 0 on the "Set of values" is working now and then the issue was resolved.
I'm going to change the issue's status for RTBC.
But I think it's better the maintainer to chose if he will to commit the patch with or without traits.
Comment #13
elberComment #14
dqdThis needs another review and further discussion since some years are gone and the previously discussed things have been partly adressed and new questions have raised around them. So new thoughts are welcome.
Comment #15
benstallings commented