24require_once DOL_DOCUMENT_ROOT .
'/core/class/fields/commonselectfield.class.php';
35 public $emptyValues = array(
'');
50 public function printInputSearchField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
54 $moreCss = $this->
getInputCss($fieldInfos, $moreCss);
55 $moreAttrib = trim((
string) $moreAttrib);
56 if (empty($moreAttrib)) $moreAttrib =
' ' . $moreAttrib;
57 $htmlName = $keyPrefix . $key . $keySuffix;
58 $value = $this->
isEmptyValue($fieldInfos, $value) ? array() : (is_string($value) ? explode(
',', $value) : (is_array($value) ? $value: array($value)));
60 $optionsList = array();
61 $options = $this->
getOptions($fieldInfos, $key);
62 foreach ($options as $optionKey => $optionInfos) {
63 $options[$optionKey] = $optionInfos[
'label'];
66 return self::$form->multiselectarray($htmlName, $optionsList, $value, 0, 0, $moreCss, 0, 0, $moreAttrib,
'',
'', (
int) (!empty($conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')));
81 public function printInputField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
83 $moreCss = $this->
getInputCss($fieldInfos, $moreCss);
84 $moreAttrib = trim((
string) $moreAttrib);
85 if (empty($moreAttrib)) $moreAttrib =
' ' . $moreAttrib;
86 $placeHolder = $fieldInfos->inputPlaceholder;
88 $autoFocus = $fieldInfos->inputAutofocus ?
' autofocus' :
'';
89 $htmlName = $keyPrefix . $key . $keySuffix;
91 $selectedValue = is_null($value) || $this->
isEmptyValue($fieldInfos, $value) ?
'' : (string) $value;
93 $options = $this->
getOptions($fieldInfos, $key,
true);
95 return self::$form->selectarray($htmlName, $options, $selectedValue, 0, 0, 0, $moreAttrib . $placeHolder . $autoFocus, 0, 0, 0,
'', $moreCss);
110 public function printOutputField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
112 $value = (string) $value;
115 $options = $this->
getOptions($fieldInfos, $key);
116 foreach ($options as $optionKey => $optionInfos) {
117 if (((
string) $optionKey) == $value) {
118 $value = $optionInfos[
'label'];
136 public function getInputCss($fieldInfos, $moreCss =
'', $defaultCss =
'')
138 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss ? $defaultCss :
'minwidth400');
153 $value = (string) $value;
155 $result = parent::verifyFieldValue($fieldInfos, $key, $value);
156 if ($result && !$this->
isEmptyValue($fieldInfos, $value)) {
157 $options = $this->
getOptions($fieldInfos, $key);
158 if (!isset($options[$value])) {
159 self::$validator->error = $langs->trans(
'RequireValidValue');
181 $htmlName = $keyPrefix . $key . $keySuffix;
182 $value =
GETPOST($htmlName,
'restricthtml');
183 $value = trim($value);
199 public function getPostFieldValue($fieldInfos, $key, $defaultValue =
null, $keyPrefix =
'', $keySuffix =
'')
201 $htmlName = $keyPrefix . $key . $keySuffix;
203 if (GETPOSTISSET($htmlName)) {
204 $value =
GETPOST($htmlName,
'alphanohtml');
206 $value = $defaultValue;
209 return $this->
isEmptyValue($fieldInfos, $value) ?
'' : $value;
225 $htmlName = $keyPrefix . $key . $keySuffix;
227 if (GETPOSTISSET($htmlName)) {
228 $value =
GETPOST($htmlName,
'array');
230 $value = $defaultValue;
247 if (!$this->
isEmptyValue($fieldInfos, $value) && is_array($value)) {
248 $alias = $fieldInfos->sqlAlias ??
't.';
249 $field = $this->db->sanitize($alias . ($fieldInfos->nameInTable ?? $key));
251 $tmp =
"'" . implode(
"','", array_map(array($this->db,
'escape'), $value)) .
"'";
252 return " AND " . $field .
" IN (" . $this->db->sanitize($tmp, 1) .
")";
267 public function getOptions($fieldInfos, $key, $addEmptyValue =
false, $reload =
false)
269 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.
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.