input.select2.php
Поле «Раскрывающийся список 2»
Вызывается из:
Смотрите описание Cms\Root\Form\Field\Select2
Исходный код
<?php
$attributes = $Field->getFieldInputAttributes(array(
'grid-margin' => $Field->getInputMargin(),
'grid-width' => $Field->getInputWidth(),
'class' => 'field-input field-input--' . $Field->type,
));
print '<span';
foreach ($attributes as $attributeName => $attributeValue) if ($attributeValue !== null) print ' ' . $attributeName . '="' . $attributeValue . '"';
print '>';
$attributes = $Field->getInputAttributes(array(
'name' => $Field->name,
'placeholder' => strval($Field->placeholder) !== '' ? htmlspecialchars($Field->placeholder) : null,
'required' => $Field->required ? '' : null,
'readonly' => $Field->readonly ? '' : null,
'disabled' => $Field->disabled ? '' : null,
'class' => 'select select2',
'id' => $Field->id('-input'),
'tabindex' => $Field->readonly ? '-1' : null,
));
print '<select';
foreach ($attributes as $attributeName => $attributeValue) if ($attributeValue !== null) print ' ' . $attributeName . '="' . $attributeValue . '"';
print '>';
if (is_array($Field->optionList) && !empty($Field->optionList)) {
$value = $Field->stringValue();
if (!isset($Field->options[''])) {
if (strval($Field->placeholder) !== '') {
print "\n" . '<option value="" data-placeholder="' . htmlspecialchars($Field->placeholder) . '">' . htmlspecialchars($Field->placeholder) . '</option>';
} else {
print "\n" . '<option value=""> </option>';
}
}
foreach ($Field->optionList as $option) {
if ($option['isGroup']) {
print "\n" . '<optgroup label="' . $Field->v($option['label']) . '">';
foreach ($option['optionList'] as $option) {
$optionValue = $option['value'];
$optionLabel = $option['label'];
print "\n" . '<option value="' . $Field->v($optionValue) . '"' . ($optionValue === $value ? ' selected=""' : '') . '>' . $Field->v($optionLabel) . '</option>';
}
print "\n" . '</optgroup>';
} else {
$optionValue = $option['value'];
$optionLabel = $option['label'];
if ($optionValue === '') {
if ($optionLabel === null || $optionLabel === false || $optionLabel === '-') continue;
}
print "\n" . '<option value="' . $Field->v($optionValue) . '"' . (strval($optionValue) === $value ? ' selected=""' : '') . '>' . $Field->v($optionLabel) . '</option>';
}
}
} elseif (strval($Field->placeholder) !== '') {
print "\n" . '<option value="" data-placeholder="' . htmlspecialchars($Field->placeholder) . '">' . htmlspecialchars($Field->placeholder) . '</option>';
} else {
print "\n" . '<option value=""> </option>';
}
print "\n" . '</select>';
print '</span>';
?>
<script>
cmsRequire(['form/script/input.select2'], init => init(document.getElementById(<?=$Field->jId('-input')?>)));
</script>