32 $options = static::getFieldOptions($fieldType);
33 if (is_scalar($value) && isset(
$options[$value]))
50 $type = $toTypeClass::getType();
51 $options = static::getFieldOptions($fieldType);
53 $key = $originalValue = $value;
56 foreach($value as
$k => $v)
70 $value = mb_strtolower((
string)
$key);
71 $value = in_array($value,
array(
'y',
'yes',
'true',
'1')) ?
'Y' :
'N';
74 $value = str_replace(
' ',
'', str_replace(
',',
'.',
$key));
75 $value = (float)$value;
78 $value = str_replace(
' ',
'',
$key);
83 $value = (string) $originalValue;
87 $value = (string)
$key;
91 if (mb_strpos($value,
'user_') ===
false
92 && mb_strpos($value,
'group_') ===
false
93 && !preg_match(
'#^[0-9]+$#', $value)
138 && isset($fieldType->
getProperty()[
'Settings'][
'ViewType'])
139 && $fieldType->
getProperty()[
'Settings'][
'ViewType'] === self::VIEW_TYPE_MENU
143 if (is_null($value) && !is_null($properties[
'Default']))
145 $value = is_array($properties[
'Default']) ? $properties[
'Default'] : [$properties[
'Default']];
148 'name' => $properties[
'Name'] ??
'',
149 'fieldName' => $field[
'Field'],
150 'options' => $properties[
'Options'] ?? [],
151 'multiple' => $properties[
'Multiple'] ??
false,
152 'selected' => is_array($value) ? $value : [$value],
157 <div data-role=
"menu-selector" data-config=
"${config}"></div>
160 $selectorValue =
null;
162 if (!is_array($value))
164 $value = (
array)$value;
167 if (\CBPHelper::isAssociativeArray($value))
169 $value = array_keys($value);
172 foreach ($value as $v)
180 $typeValue[] = (string)$v;
185 if (empty($typeValue))
190 $className = static::generateControlClassName($fieldType, $field);
191 $selectorAttributes =
'';
195 if ($allowSelection && $isPublicControl)
197 $selectorAttributes = sprintf(
198 'data-role="inline-selector-target" data-property="%s" ',
205 $selectorAttributes .=
'size="5" multiple ';
208 $renderResult = sprintf(
209 '<select id="%s" class="%s" name="%s%s" %s>',
217 $settings = static::getFieldSettings($fieldType);
219 $showEmptyValue = isset(
$settings[
'ShowEmptyValue']) ? \CBPHelper::getBool(
$settings[
'ShowEmptyValue']) :
null;
220 if (($showEmptyValue ===
null && !$fieldType->
isMultiple()) || $showEmptyValue ===
true)
222 $renderResult .=
'<option value="">['.Loc::getMessage(
'BPDT_SELECT_NOT_SET').
']</option>';
231 if(!is_array($group))
236 $name = isset($group[
'name']) ? $group[
'name'] :
'';
240 $renderResult .=
'<optgroup label="'.htmlspecialcharsbx(
$name).
'">';
243 $options = isset($group[
'items']) && is_array($group[
'items']) ? $group[
'items'] :
array();
246 $renderResult .=
'<option value="';
248 $renderResult .=
'"';
250 if(in_array((
string)
$k, $typeValue,
true))
252 $renderResult .=
' selected';
255 $renderResult .=
'>';
257 $renderResult .=
'</option>';
262 $renderResult .=
'</optgroup>';
268 $options = static::getFieldOptions($fieldType);
275 if ($allowSelection && $selectorValue && $isPublicControl)
277 $renderResult .= sprintf(
278 '<option value="%s" selected data-role="expression">%s</option>',
284 $renderResult .=
'</select>';
286 if ($allowSelection && !$isPublicControl)
288 $renderResult .= static::renderControlSelector($field, $selectorValue,
true,
'', $fieldType);
291 return $renderResult;
315 $allowSelection =
false;
318 return static::renderControl($fieldType, $field, $value, $allowSelection, $renderMode);
333 $allowSelection =
false;
336 return static::renderControl($fieldType, $field, $value, $allowSelection, $renderMode);
345 public static function renderControlOptions(FieldType $fieldType, $callbackFunctionName, $value)
347 $options = static::getFieldOptions($fieldType);
352 if ((
string)
$k !== (
string)$v)
353 $str .=
'['.$k.
']'.$v;
361 $renderResult =
'<textarea id="WFSFormOptionsX'.$rnd.
'" rows="5" cols="30">'.
htmlspecialcharsbx(
$str).
'</textarea><br />';
362 $renderResult .= Loc::getMessage(
'BPDT_SELECT_OPTIONS1').
'<br />';
363 $renderResult .= Loc::getMessage(
'BPDT_SELECT_OPTIONS2').
'<br />';
364 $renderResult .=
'<script>
365 function WFSFormOptionsXFunction'.$rnd.
'()
368 var i, id, val, str = document.getElementById("WFSFormOptionsX'.$rnd.
'").value;
370 var arr = str.split(/[\r\n]+/);
371 var p, re = /\[([^\]]+)\].+/;
374 str = arr[i].replace(/^\s+|\s+$/g, \'\');
380 p = str.indexOf(\']\');
382 val = str.substr(p + 1);
396 $renderResult .=
'<input type="button" onclick="'.htmlspecialcharsbx($callbackFunctionName)
397 .
'(WFSFormOptionsXFunction'.$rnd.
'())" value="'.Loc::getMessage(
'BPDT_SELECT_OPTIONS3').
'">';
399 return $renderResult;
412 !empty(static::getFieldOptions($fieldType))
418 if (!empty(
$errors) && $value ===
null)
420 $lastErrorKey = array_key_last(
$errors);
421 if (!array_key_exists(
'parameter',
$errors[$lastErrorKey]))
423 $errors[$lastErrorKey][
'parameter'] = static::generateControlName($field);
426 static::cleanErrors();
441 $name = $field[
'Field'];
444 if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value))
446 $value = array_unique($value);
448 return parent::extractValueMultiple($fieldType, $field,
$request);
457 public static function formatValueMultiple(FieldType $fieldType, $value, $format =
'printable')
459 if (\CBPHelper::isAssociativeArray($value))
461 $value = array_keys($value);
463 return parent::formatValueMultiple($fieldType, $value, $format);
472 public static function formatValueSingle(FieldType $fieldType, $value, $format =
'printable')
474 if (\CBPHelper::isAssociativeArray($value))
476 $keys = array_keys($value);
477 $value = isset($keys[0]) ? $keys[0] :
null;
480 if (is_array($value))
482 $value = current(array_values($value));
485 return parent::formatValueSingle($fieldType, $value, $format);
496 if (\CBPHelper::isAssociativeArray($value))
498 $value = array_keys($value);
500 return parent::convertValueMultiple($fieldType, $value, $toTypeClass);
508 protected static function getFieldOptions(FieldType $fieldType)
510 $options = $fieldType->getOptions();
511 return self::normalizeOptions(
$options);
519 protected static function getFieldSettings(FieldType $fieldType)
521 return $fieldType->getSettings();
528 protected static function normalizeOptions(
$options)
535 if (is_array($value) &&
sizeof($value) == 2)
537 $v = array_values($value);
554 $map = $fieldType->getSettings()[
'ExternalValues'] ??
null;
560 return parent::externalizeValue($fieldType,
$context, $value);
565 if (\CBPHelper::isAssociativeArray($baseValue))
567 $baseValue = array_keys($baseValue);
569 if (\CBPHelper::isAssociativeArray($appendValue))
571 $appendValue = array_keys($appendValue);
574 return parent::mergeValue($fieldType, $baseValue, $appendValue);
579 $options = static::getFieldOptions($fieldType);
591 if (!(is_string($value) || is_int($value)))
602 'code' =>
'ErrorValue',
603 'message' => Loc::getMessage(
'BPDT_SELECT_INVALID'),
617 $value = parent::validateValueMultiple($value, $fieldType);
619 return array_values(array_filter($value,
static fn($v) => ($v !==
null)));
626 $options = static::getFieldOptions($fieldType);
627 $property[
'Options'] = array_map(
628 fn($value,
$name) => [
'value' => $value,
'name' =>
$name],
634 return parent::convertPropertyToView($fieldType, $viewMode, $property);
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)