-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
FIX: required extrafields: bad check to see if empty + prevent letting it empty (Issue #11169) #11202
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"> </option>'; | ||
if(empty($required)) $out.='<option value="0"> </option>'; | ||
foreach ($param['options'] as $key => $val) | ||
{ | ||
if ((string) $key == '') continue; | ||
|
@@ -1829,7 +1829,7 @@ function showSeparator($key, $object) | |
function setOptionalsFromPost($extralabels, &$object, $onlykey='') | ||
{ | ||
global $_POST, $langs; | ||
$nofillrequired='';// For error when required field left blank | ||
$nofillrequired=0;// For error when required field left blank | ||
$error_field_required = array(); | ||
|
||
if (is_array($this->attributes[$object->table_element]['label'])) $extralabels=$this->attributes[$object->table_element]['label']; | ||
|
@@ -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])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Still, making the '0' choice available if the field is required seems an issue to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "tooltips" has right for combo. |
||
{ | ||
//print 'ccc'.$value.'-'.$this->attributes[$object->table_element]['required'][$key]; | ||
$nofillrequired++; | ||
|
There was a problem hiding this comment.
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.