Система управления «Сайт PRO»
Версия 20240107

input.multiple.php

Поле «Множественный список»

Вызывается из:

Смотрите описание Cms\Root\Form\Field\Multiple

Исходный код
<?php

$attributes = $Field->getFieldInputAttributes(array(
    'grid-margin' => $Field->getInputMargin(),
    'grid-width' => $Field->getInputWidth(),
    'class' => 'field-input field-input--' . $Field->type,
    'id' => $Field->id('-input'),
    'data-name' => $Field->name,
));
print '<span';
foreach ($attributes as $attributeName => $attributeValue) if ($attributeValue !== null) print ' ' . $attributeName . '="' . $attributeValue . '"';
print '>';

$attributes = $Field->getInputAttributes(array(
    'type' => 'checkbox',
    'name' => $Field->name ? $Field->name . '[]' : $Field->name,
    'placeholder' => strval($Field->placeholder) !== '' ? htmlspecialchars($Field->placeholder) : null,
    'data-required' => $Field->required ? 'Y' : null,
    'readonly' => $Field->readonly ? '' : null,
    'disabled' => $Field->disabled ? '' : null,
    'class' => 'input--checkbox',
    'onclick' => $Field->readonly ? 'return false' : null,
));
if (is_array($Field->optionList) && count($Field->optionList)) {
    $value = $Field->stringArrayValue();
    foreach ($Field->optionList as $option) {
        if ($option['isGroup']) {
            print '<span class="input-group">';
            if ($option['label'] !== '') print '<span class="input-title">' . $option['label'] . '</span>';
            foreach ($option['optionList'] as $option) {
                $attributes['value'] = $Field->v($option['value']);
                $attributes['checked'] = in_array(strval($option['value']), $value, true) ? '' : null;
                print '<label class="input-label input-label--checkbox">';
                print '<input';
                foreach ($attributes as $attributeName => $attributeValue) if ($attributeValue !== null) print ' ' . $attributeName . '="' . $attributeValue . '"';
                print '>';
                print '<span class="label-text">' . $option['label'] . '</span>';
                print '</label>';
            }
            print '</span>';
        } else {
            $attributes['value'] = $Field->v($option['value']);
            $attributes['checked'] = in_array(strval($option['value']), $value, true) ? '' : null;
            print '<label class="input-label input-label--checkbox">';
            print '<input';
            foreach ($attributes as $attributeName => $attributeValue) if ($attributeValue !== null) print ' ' . $attributeName . '="' . $attributeValue . '"';
            print '>';
            print '<span class="label-text">' . $option['label'] . '</span>';
            print '</label>';
        }
    }
} else {
    $attributes['value'] = '';
    print '<label class="input-label input-label--checkbox">';
    print '<input';
    foreach ($attributes as $attributeName => $attributeValue) if ($attributeValue !== null) print ' ' . $attributeName . '="' . $attributeValue . '"';
    print '>';
    print '<span class="label-text"></span>';
    print '</label>';
}

print '</span>';

?>

<script>
cmsRequire(['form/script/input.multiple'], init => init(document.getElementById(<?=$Field->jId('-input')?>)));
</script>