25require_once DOL_DOCUMENT_ROOT .
'/core/class/fields/commonselectfield.class.php';
36 public $emptyValues = array(
'');
51 public function printInputSearchField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
55 $moreCss = $this->
getInputCss($fieldInfos, $moreCss);
56 $moreAttrib = trim((
string) $moreAttrib);
57 if (empty($moreAttrib)) {
58 $moreAttrib =
' ' . $moreAttrib;
60 $htmlName = $keyPrefix . $key . $keySuffix;
61 $value = $this->
isEmptyValue($fieldInfos, $value) ? array() : (is_string($value) ? explode(
',', $value) : (is_array($value) ? $value : array($value)));
63 $optionsList = array();
64 $options = $this->
getOptions($fieldInfos, $key);
65 foreach ($options as $optionKey => $optionInfos) {
66 $options[$optionKey] = $optionInfos[
'label'];
69 return self::$form->multiselectarray($htmlName, $optionsList, $value, 0, 0, $moreCss, 0, 0, $moreAttrib,
'',
'', (
int) (!empty(
$conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')));
84 public function printInputField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
86 $moreCss = $this->
getInputCss($fieldInfos, $moreCss);
87 $moreAttrib = trim((
string) $moreAttrib);
88 if (empty($moreAttrib)) {
89 $moreAttrib =
' ' . $moreAttrib;
91 $placeHolder = $fieldInfos->inputPlaceholder;
92 if (!empty($placeHolder)) {
93 $placeHolder =
' placeholder="' . dolPrintHTMLForAttribute($placeHolder) .
'"';
95 $autoFocus = $fieldInfos->inputAutofocus ?
' autofocus' :
'';
96 $htmlName = $keyPrefix . $key . $keySuffix;
98 $selectedValue = is_null($value) || $this->
isEmptyValue($fieldInfos, $value) ?
'' : (string) $value;
100 $options = $this->
getOptions($fieldInfos, $key,
true);
102 return self::$form->selectarray($htmlName, $options, $selectedValue, 0, 0, 0, $moreAttrib . $placeHolder . $autoFocus, 0, 0, 0,
'', $moreCss);
117 public function printOutputField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
119 $value = (string) $value;
122 $options = $this->
getOptions($fieldInfos, $key);
123 foreach ($options as $optionKey => $optionInfos) {
124 if (((
string) $optionKey) == $value) {
125 $value = $optionInfos[
'label'];
143 public function getInputCss($fieldInfos, $moreCss =
'', $defaultCss =
'')
145 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss ? $defaultCss :
'minwidth400');
160 $value = (string) $value;
162 $result = parent::verifyFieldValue($fieldInfos, $key, $value);
163 if ($result && !$this->
isEmptyValue($fieldInfos, $value)) {
164 $options = $this->
getOptions($fieldInfos, $key);
165 if (!isset($options[$value])) {
166 self::$validator->error = $langs->trans(
'RequireValidValue');
188 $htmlName = $keyPrefix . $key . $keySuffix;
189 $value =
GETPOST($htmlName,
'restricthtml');
190 $value = trim($value);
206 public function getPostFieldValue($fieldInfos, $key, $defaultValue =
null, $keyPrefix =
'', $keySuffix =
'')
208 $htmlName = $keyPrefix . $key . $keySuffix;
211 $value =
GETPOST($htmlName,
'alphanohtml');
213 $value = $defaultValue;
216 return $this->
isEmptyValue($fieldInfos, $value) ?
'' : $value;
232 $htmlName = $keyPrefix . $key . $keySuffix;
235 $value =
GETPOST($htmlName,
'array');
237 $value = $defaultValue;
254 if (!$this->
isEmptyValue($fieldInfos, $value) && is_array($value)) {
255 $alias = $fieldInfos->sqlAlias ??
't.';
256 $field = $this->db->sanitize($alias . ($fieldInfos->nameInTable ?? $key));
258 $sanitizedSqlIn =
"'" . implode(
"','", array_map(array($this->db,
'escape'), $value)) .
"'";
259 $sqlPartialCond =
" AND " . $field .
" IN (" . $sanitizedSqlIn .
")";
260 return $sqlPartialCond;
275 public function getOptions($fieldInfos, $key, $addEmptyValue =
false, $reload =
false)
277 return parent::getOptions($fieldInfos, $key, $addEmptyValue, $reload);
isEmptyValue($fieldInfos, $value, $emptyValues=null)
Check if the value is deemed as empty.
Class to common select field.
getPostFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get field value from GET/POST.
getInputCss($fieldInfos, $moreCss='', $defaultCss='')
Get input CSS.
sqlFilterSearchField($fieldInfos, $key, $value)
Get sql filter for search field.
getPostSearchFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get search field value from GET/POST.
printInputSearchField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input search field into a page.
getOptions($fieldInfos, $key, $addEmptyValue=false, $reload=false)
Get list of options.
printInputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input field into a page.
verifyFieldValue($fieldInfos, $key, $value)
Verify if the field value is valid.
verifyPostFieldValue($fieldInfos, $key, $keyPrefix='', $keySuffix='')
Verify if the field value from GET/POST is valid.
printOutputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to show a field into a page.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.