130 $selectorValue =
null;
132 if (!is_array($value))
134 $value = (array)$value;
137 if (\CBPHelper::isAssociativeArray($value))
139 $value = array_keys($value);
142 foreach ($value as $v)
144 if ($allowSelection && \CBPActivity::isExpression($v))
150 $typeValue[] = (string)$v;
155 if (empty($typeValue))
160 $className = static::generateControlClassName($fieldType, $field);
161 $selectorAttributes =
'';
165 if ($allowSelection && $isPublicControl)
167 $selectorAttributes = sprintf(
168 'data-role="inline-selector-target" data-property="%s" ',
169 htmlspecialcharsbx(Main\Web\Json::encode($fieldType->
getProperty()))
175 $selectorAttributes .=
'size="5" multiple ';
178 $renderResult = sprintf(
179 '<select id="%s" class="%s" name="%s%s" %s>',
180 htmlspecialcharsbx(static::generateControlId($field)),
181 ($isPublicControl ? htmlspecialcharsbx($className) :
''),
182 htmlspecialcharsbx(static::generateControlName($field)),
187 $settings = static::getFieldSettings($fieldType);
189 $showEmptyValue = isset($settings[
'ShowEmptyValue']) ? \CBPHelper::getBool($settings[
'ShowEmptyValue']) :
null;
190 if (($showEmptyValue ===
null && !$fieldType->
isMultiple()) || $showEmptyValue ===
true)
192 $renderResult .=
'<option value="">['.Loc::getMessage(
'BPDT_SELECT_NOT_SET').
']</option>';
195 $groups = $settings[
'Groups'] ??
null;
197 if(is_array($groups) && !empty($groups))
199 foreach($groups as $group)
201 if(!is_array($group))
206 $name = isset($group[
'name']) ? $group[
'name'] :
'';
210 $renderResult .=
'<optgroup label="'.htmlspecialcharsbx($name).
'">';
213 $options = isset($group[
'items']) && is_array($group[
'items']) ? $group[
'items'] : array();
214 foreach($options as $k => $v)
216 $renderResult .=
'<option value="';
217 $renderResult .= htmlspecialcharsbx($k);
218 $renderResult .=
'"';
220 if(in_array((
string)$k, $typeValue,
true))
222 $renderResult .=
' selected';
225 $renderResult .=
'>';
226 $renderResult .= htmlspecialcharsbx($v);
227 $renderResult .=
'</option>';
232 $renderResult .=
'</optgroup>';
238 $options = static::getFieldOptions($fieldType);
239 foreach ($options as $k => $v)
241 $renderResult .=
'<option value="'.htmlspecialcharsbx($k).
'"'.(in_array((
string)$k, $typeValue) ?
' selected' :
'').
'>'.htmlspecialcharsbx(htmlspecialcharsback($v)).
'</option>';
245 if ($allowSelection && $selectorValue && $isPublicControl)
247 $renderResult .= sprintf(
248 '<option value="%s" selected data-role="expression">%s</option>',
249 htmlspecialcharsbx($selectorValue),
250 htmlspecialcharsbx($selectorValue)
254 $renderResult .=
'</select>';
256 if ($allowSelection && !$isPublicControl)
258 $renderResult .= static::renderControlSelector($field, $selectorValue,
true,
'', $fieldType);
261 return $renderResult;
317 $options = static::getFieldOptions($fieldType);
320 foreach ($options as $k => $v)
322 if ((
string)$k !== (
string)$v)
323 $str .=
'['.$k.
']'.$v;
331 $renderResult =
'<textarea id="WFSFormOptionsX'.$rnd.
'" rows="5" cols="30">'.htmlspecialcharsbx($str).
'</textarea><br />';
334 $renderResult .=
'<script type="text/javascript">
335 function WFSFormOptionsXFunction'.$rnd.
'()
338 var i, id, val, str = document.getElementById("WFSFormOptionsX'.$rnd.
'").value;
340 var arr = str.split(/[\r\n]+/);
341 var p, re = /\[([^\]]+)\].+/;
344 str = arr[i].replace(/^\s+|\s+$/g, \'\');
350 p = str.indexOf(\']\');
352 val = str.substr(p + 1);
366 $renderResult .=
'<input type="button" onclick="'.htmlspecialcharsbx($callbackFunctionName)
367 .
'(WFSFormOptionsXFunction'.$rnd.
'())" value="'.
Loc::getMessage(
'BPDT_SELECT_OPTIONS3').
'">';
369 return $renderResult;
380 $value = parent::extractValue($fieldType, $field, $request);
382 !empty(static::getFieldOptions($fieldType))
388 if (!empty(
$errors) && $value ===
null)
390 $lastErrorKey = array_key_last(
$errors);
391 if (!array_key_exists(
'parameter',
$errors[$lastErrorKey]))
393 $errors[$lastErrorKey][
'parameter'] = static::generateControlName($field);
396 static::cleanErrors();
411 $name = $field[
'Field'];
412 $value = isset($request[$name]) ? $request[$name] : array();
414 if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value))
415 $value = array($value);
416 $value = array_unique($value);
417 $request[$name] = $value;
418 return parent::extractValueMultiple($fieldType, $field, $request);
429 if (\CBPHelper::isAssociativeArray($value))
431 $value = array_keys($value);
433 return parent::formatValueMultiple($fieldType, $value, $format);
444 if (\CBPHelper::isAssociativeArray($value))
446 $keys = array_keys($value);
447 $value = isset($keys[0]) ? $keys[0] :
null;
450 if (is_array($value))
452 $value = current(array_values($value));
455 return parent::formatValueSingle($fieldType, $value, $format);
466 if (\CBPHelper::isAssociativeArray($value))
468 $value = array_keys($value);
470 return parent::convertValueMultiple($fieldType, $value, $toTypeClass);
535 if (\CBPHelper::isAssociativeArray($baseValue))
537 $baseValue = array_keys($baseValue);
539 if (\CBPHelper::isAssociativeArray($appendValue))
541 $appendValue = array_keys($appendValue);
544 return parent::mergeValue($fieldType, $baseValue, $appendValue);
549 $options = static::getFieldOptions($fieldType);
551 if (\CBPActivity::isExpression($value) || empty($options))
561 if (!(is_string($value) || is_int($value)))
566 if (!isset($options[$value]))
568 $key = array_search($value, $options,
false);
572 'code' =>
'ErrorValue',