Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the loris form '0' emptying issue #2781

Merged
merged 2 commits into from
Jun 5, 2017

Conversation

sruthymathew123
Copy link
Contributor

@sruthymathew123 sruthymathew123 commented May 3, 2017

Loris form $this->form->addRule("value", "Required", 'required'); sets the 'required fail' for the value '0' which is sometimes a valid value/option for some instruments.

empty($value) is true for 0 which cause the issue.

So going for a better option to overcome that issue.

@sruthymathew123 sruthymathew123 added the Category: Bug PR or issue that aims to report or fix a bug label May 3, 2017
@sruthymathew123 sruthymathew123 added this to the 17.0 milestone May 3, 2017
@AnyhowStep
Copy link
Contributor

We could start by not returning empty arrays when we mean "there is no value here". Gee, I wonder, what value has the meaning of not having a value?

@@ -1180,7 +1180,7 @@ class LorisForm

if (isset($el['required'])
&& $el['required'] === true
&& empty($value)
&& (is_null($value) || (empty($value) && $value !=0))
Copy link
Contributor

@johnsaigle johnsaigle May 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this just read

&& $value)

? This will evaluate to false in each of the cases you want here.

http://stackoverflow.com/questions/2382490/how-does-true-false-work-in-php#2382510

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be this because empty(0) evaluates to true even though it should be false

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I made a mistake, good catch

@@ -1180,7 +1180,7 @@ class LorisForm

if (isset($el['required'])
&& $el['required'] === true
&& empty($value)
&& (is_null($value) || (empty($value) && $value !=0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@driusan suggests that we should just use $value === "" instead of this, @sruthymathew123 can you see if that works?

@johnsaigle johnsaigle dismissed their stale review May 4, 2017 18:59

made a mistake!

@sruthymathew123
Copy link
Contributor Author

@jstirling91 It is working for that case and anyway wide testing is needed.
Done the changes requested.

@driusan
Copy link
Collaborator

driusan commented May 31, 2017

@jstirling91 I think this is in your court. Are your changes requested done or can the review be dismissed?

@jstirling91 jstirling91 dismissed their stale review June 2, 2017 19:12

Comments addressed

@jstirling91
Copy link
Contributor

@driusan the comments have been addressed. Though this pull request is to 17.0-dev, do we want to add this to a 17.0.4 release or should we switch it to 17.1-dev?

@driusan
Copy link
Collaborator

driusan commented Jun 2, 2017

@jstirling91 This plus your API fix (once it passes Travis) in a 17.0.4 sounds good to me.

Copy link
Collaborator

@driusan driusan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@driusan driusan merged commit 0951825 into aces:17.0-dev Jun 5, 2017
taracampbell pushed a commit to taracampbell/Loris that referenced this pull request Jun 13, 2017
$this->form->addRule("value", "Required", 'required'); sets the 'required fail' when the user submits a value of "0", because empty($value) is true for 0.

This updates the code to explicitly check for the empty string to detect no input, and avoids PHP's empty() function for validation.
jstirling91 pushed a commit to jstirling91/Loris that referenced this pull request Jun 21, 2017
$this->form->addRule("value", "Required", 'required'); sets the 'required fail' when the user submits a value of "0", because empty($value) is true for 0.

This updates the code to explicitly check for the empty string to detect no input, and avoids PHP's empty() function for validation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Bug PR or issue that aims to report or fix a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants