User tests: Successful: Unsuccessful:
Pull Request for allowing 0
as value in com_fields fields.
Changing the value checks from a generic boolean check to one that triggers on an empty string (or null).
Further testing:
Check with different options (eg no value entered), enable the "multiple" feature, set a default value.
Check with other formfields like text and enter a 0.
None
Status | New | ⇒ | Pending |
Category | ⇒ | Administration Components Front End |
That will not work with if $value is an empty array()
also == '' is not good , you need strlen, e.g. integer value 0 is not an empty value
best is:
if ((!is_array($value) && !strlen($value)) || (is_array($value) && !count($value)))
Also the fix needs to go to all layouts, not only to the radio / checkboxes / list fields,
i mean that i suggest to change titile of this PR and apply fix to all fields ?
Are values always strings?
I think so, yes. I wasn't able to get a different type.
That will not work with if $value is an empty array()
I wasn't able to get an empty array there. Do you know a way to get that?
integer value 0 is not an empty value
As said above, the value always was a string when I debugged. So no integers and no arrays.
I prefer that simple code vs your code solution because it is much more readable. As long as it does the job of course.
If the value may be an empty array, I'd rather cast it to array before the check and simplify the code again (it's cast to array afterwards anyway).
Also the fix needs to go to all layouts, not only to the radio / checkboxes / list fields,
i mean that i suggest to change titile of this PR and apply fix to all fields ?
Hmm, you're right. Text is also affected and probably others as well.
Title |
|
Title |
|
Added the other formfields as well and found some other places were it also needed to be changed so the text formfield works with 0 as value.
as $field->value == '' doesn't let '0' pass.
It worked fine for me. Because '0' is a string an not an integer (not 0) the comparision work perfect. The value also never was a null for me, it was always empty if not set. I don't think JForm will ever return a null or an integer there, it's always a string (or an array of strings).
Were you able to break that code or is that just based on reviewing it?
Just by review, to be on the safe side as JForm was not involved, only database query stuff.
as JForm was not involved,
Ah, I was assuming it is coming from there but I didn't track it down.
Since we store the values in the database as text, I wouldn't expect it magically become an integer or null anyway. As long as there is no case where it could become null
, I don't see why we should add check for null
. But maybe I missed a case? I just did some tests and debugged it
I like to be on the safe side
I prefer simpler code
But in the end I don't care that much as long as it works.
I have tested this item
Tested with lists and texts
I have tested this item
It only works with radio and list,
-- it does not work with checkboxes
More specifically:
-- it does not work when you only select the zero-value checkbox element (and do not select other checkbox elements)
Ah and can you mark a successfull test here please?
I have tested this item
yes, since the case described in my last post, is being fixed in a different PR,
arguably it could have been in this one
Milestone |
Added: |
Status | Pending | ⇒ | Ready to Commit |
RTC
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-12-06 21:59:57 |
Closed_By | ⇒ | rdeutz |
Category | Administration Components Front End | ⇒ | Administration com_fields Front End Components |
Are values always strings? I guess so, because of if they are ever integers,
0 == ''
.