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

FIX: required extrafields: bad check to see if empty + prevent letting it empty (Issue #11169) #11202

Closed
wants to merge 2 commits into from

Conversation

ATM-Marc
Copy link
Contributor

No description provided.

@@ -1860,8 +1860,7 @@ function setOptionalsFromPost($extralabels, &$object, $onlykey='')
if ($this->attributes[$object->table_element]['required'][$key]) // Value is required
{
// Check if empty without using GETPOST, value can be alpha, int, array, etc...
if ((! is_array($_POST["options_".$key]) && empty($_POST["options_".$key]) && $_POST["options_".$key] != '0')
|| (is_array($_POST["options_".$key]) && empty($_POST["options_".$key])))
if (empty($_POST["options_".$key]))
Copy link
Member

@eldy eldy May 18, 2019

Choose a reason for hiding this comment

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

If value is '0', empty will be true, so it will return an error.
For a combo list with multiple choice with first choice that has key '0' and label "My value 0" will not be possible to be selected. Old code seems good.

Copy link
Contributor Author

@ATM-Marc ATM-Marc May 18, 2019

Choose a reason for hiding this comment

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

I reverted to the old check but I don't really understand your use case. The tooltips for checkbox- and select-typed extrafields say that the keys should not be '0', so that Dolibarr itself could propose the empty choice with '0' key and empty label. Is the tooltip incorrect ?

Still, making the '0' choice available if the field is required seems an issue to me.

Copy link
Member

@eldy eldy May 31, 2019

Choose a reason for hiding this comment

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

The "tooltips" has right for combo.
But the test should works also for string or value. And for string '0' is not empty.
I pushed a better fix...

@eldy eldy added the Discussion Some questions or discussions are opened and wait answers of author or other people to be processed label May 18, 2019
@@ -1057,7 +1057,7 @@ function showInputField($key, $value, $moreparam='', $keysuffix='', $keyprefix='
}

$out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>';
$out.='<option value="0">&nbsp;</option>';
if(empty($required)) $out.='<option value="0">&nbsp;</option>';
Copy link
Member

Choose a reason for hiding this comment

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

If you remove this line when field is required, it means the combo list will be automatically set to a default value (the first one). The record will be saved with a value that was not decided/defined explicitely by user. Why setting the default value on first value and not last one.
When a field is mandatory, we want the user to enter it and if we automatically set it to a random value (first one is same than random), we make the oposite of what we want. The check is done later (except if bug) after submitting. We can also avoid empty value by adding a required HTML 5 flag may be.

eldy added a commit that referenced this pull request May 31, 2019
@eldy eldy closed this Jun 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Some questions or discussions are opened and wait answers of author or other people to be processed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants