? Success

User tests: Successful: Unsuccessful:

avatar Bakual
Bakual
7 Nov 2016

Pull Request for allowing 0 as value in com_fields fields.

Summary of Changes

Changing the value checks from a generic boolean check to one that triggers on an empty string (or null).

Testing Instructions

  1. Create a custom field. If it's a list type with at least one option containing a 0 as value. Eg
    yesno
  2. Select the 0 value (eg "No") in the item and save.
  3. Check the item in frontend. Before PR the field will not be shown, after the PR the field will show with proper option.

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.

Documentation Changes Required

None

avatar Bakual Bakual - open - 7 Nov 2016
avatar Bakual Bakual - change - 7 Nov 2016
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 7 Nov 2016
Category Administration Components Front End
avatar mahagr
mahagr - comment - 7 Nov 2016

Are values always strings? I guess so, because of if they are ever integers, 0 == ''.

avatar ggppdk
ggppdk - comment - 7 Nov 2016

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)))
avatar ggppdk
ggppdk - comment - 7 Nov 2016

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 ?

avatar Bakual
Bakual - comment - 7 Nov 2016

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).

avatar Bakual
Bakual - comment - 7 Nov 2016

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.

avatar Bakual Bakual - change - 7 Nov 2016
Title
[com_fields] Allow zero as value in list fields
[com_fields] Allow zero as value in fields
avatar Bakual Bakual - edited - 7 Nov 2016
avatar Bakual Bakual - change - 7 Nov 2016
Title
[com_fields] Allow zero as value in list fields
[com_fields] Allow zero as value in fields
avatar Bakual Bakual - change - 7 Nov 2016
The description was changed
avatar Bakual Bakual - edited - 7 Nov 2016
avatar Bakual
Bakual - comment - 7 Nov 2016

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.

avatar laoneo
laoneo - comment - 14 Nov 2016

In #12886 if checked additionally if the value is null like $field->value === '' || $field->value === null as $field->value == '' doesn't let '0' pass.

avatar Bakual
Bakual - comment - 14 Nov 2016

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?

avatar laoneo
laoneo - comment - 14 Nov 2016

Just by review, to be on the safe side as JForm was not involved, only database query stuff.

avatar Bakual
Bakual - comment - 14 Nov 2016

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 ?

avatar laoneo
laoneo - comment - 14 Nov 2016

I like to be on the safe side ?

avatar Bakual
Bakual - comment - 14 Nov 2016

I prefer simpler code ?

But in the end I don't care that much as long as it works.

avatar laoneo laoneo - test_item - 14 Nov 2016 - Tested successfully
avatar laoneo
laoneo - comment - 14 Nov 2016

I have tested this item successfully on e162c06

Tested with lists and texts


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12807.

avatar ggppdk
ggppdk - comment - 4 Dec 2016

I have tested this item ? unsuccessfully on e162c06

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)


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12807.

avatar ggppdk ggppdk - test_item - 4 Dec 2016 - Tested unsuccessfully
avatar Bakual
Bakual - comment - 4 Dec 2016

That's actually a different issue. See PR #12886 from Allon for that.

avatar Bakual
Bakual - comment - 4 Dec 2016

Ah and can you mark a successfull test here please? ?

avatar ggppdk
ggppdk - comment - 4 Dec 2016

I have tested this item successfully on e162c06

yes, since the case described in my last post, is being fixed in a different PR,
arguably it could have been in this one


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12807.

avatar ggppdk ggppdk - test_item - 4 Dec 2016 - Tested successfully
avatar Bakual Bakual - change - 4 Dec 2016
Milestone Added:
avatar jeckodevelopment jeckodevelopment - change - 4 Dec 2016
Status Pending Ready to Commit
avatar jeckodevelopment
jeckodevelopment - comment - 4 Dec 2016

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12807.

avatar rdeutz rdeutz - reference | 0be0f9e - 6 Dec 16
avatar rdeutz rdeutz - merge - 6 Dec 2016
avatar rdeutz rdeutz - close - 6 Dec 2016
avatar rdeutz rdeutz - change - 6 Dec 2016
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
avatar rdeutz rdeutz - close - 6 Dec 2016
avatar rdeutz rdeutz - merge - 6 Dec 2016
avatar joomla-cms-bot joomla-cms-bot - change - 6 Dec 2016
Category Administration Components Front End Administration com_fields Front End Components
avatar Bakual Bakual - head_ref_deleted - 6 Dec 2016

Add a Comment

Login with GitHub to post a comment