chg: [ui:genericDropdownField] Allow using select2 on dropdown field

develop-unstable
Sami Mokaddem 2023-01-17 09:19:40 +01:00
parent 715ba1d75b
commit 2a754160ef
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 12 additions and 0 deletions

View File

@ -19,6 +19,9 @@ if (!empty($fieldData['label'])) {
if ($controlParams['options'] instanceof \Cake\ORM\Query) { if ($controlParams['options'] instanceof \Cake\ORM\Query) {
$controlParams['options'] = $controlParams['options']->all()->toList(); $controlParams['options'] = $controlParams['options']->all()->toList();
} }
if (!empty($fieldData['select2'])) {
$controlParams['class'] .= ' select2-input';
}
if (in_array('_custom', array_keys($controlParams['options']))) { if (in_array('_custom', array_keys($controlParams['options']))) {
$customInputValue = $this->Form->getSourceValue($fieldData['field']); $customInputValue = $this->Form->getSourceValue($fieldData['field']);
if (!in_array($customInputValue, $controlParams['options'])) { if (!in_array($customInputValue, $controlParams['options'])) {
@ -49,6 +52,15 @@ echo $this->FormFieldMassage->prepareFormElement($this->Form, $controlParams, $f
$select.attr('onclick', 'toggleFreetextSelectField(this)') $select.attr('onclick', 'toggleFreetextSelectField(this)')
$select.parent().find('input.custom-value').attr('oninput', 'updateAssociatedSelect(this)') $select.parent().find('input.custom-value').attr('oninput', 'updateAssociatedSelect(this)')
updateAssociatedSelect($select.parent().find('input.custom-value')[0]) updateAssociatedSelect($select.parent().find('input.custom-value')[0])
<?php if (!empty($fieldData['select2'])) : ?>
let $container = $select.closest('.modal-dialog')
if ($container.length == 0) {
$container = $(document.body)
}
$select.select2({
dropdownParent: $container,
})
<?php endif; ?>
}) })
})() })()