Remove "allowClear" and tidy up #2459
Allow clear is not necessary, equivalent of allowClear false is "placeholder" and allowClear true is "emptyOption".
This commit is contained in:
parent
1ee0250441
commit
4aca2d40ff
|
|
@ -112,8 +112,6 @@ class Relation extends FormWidgetBase
|
|||
$field->type = 'dropdown';
|
||||
}
|
||||
|
||||
$field->placeholder = $this->emptyOption;
|
||||
|
||||
// It is safe to assume that if the model and related model are of
|
||||
// the exact same class, then it cannot be related to itself
|
||||
if ($model->exists && (get_class($model) == get_class($relationModel))) {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,7 @@
|
|||
<?php
|
||||
$fieldOptions = $field->options();
|
||||
$useSearch = $field->getConfig('showSearch', true);
|
||||
$allowClear = $field->getConfig('allowClear', false);
|
||||
// If allowClear is true, define a default placeholder in case there is not one already defined.
|
||||
if ($allowClear == true)
|
||||
{
|
||||
$field->placeholder = $field->getConfig('placeholder', e(trans('backend::lang.form.select_placeholder')));
|
||||
}
|
||||
$emptyOption = $field->getConfig('emptyOption', $field->placeholder);
|
||||
?>
|
||||
<!-- Dropdown -->
|
||||
<?php if ($this->previewMode): ?>
|
||||
|
|
@ -15,10 +10,13 @@
|
|||
<select
|
||||
id="<?= $field->getId() ?>"
|
||||
name="<?= $field->getName() ?>"
|
||||
class="form-control custom-select <?= $useSearch ? '' : 'select-no-search' ?> <?= $allowClear ? 'select-allow-clear' : '' ?>"
|
||||
class="form-control custom-select <?= $useSearch ? '' : 'select-no-search' ?>"
|
||||
<?= $field->getAttributes() ?>
|
||||
<?= $field->placeholder ? 'data-placeholder="'.e(trans($field->placeholder)).'"' : '' ?>
|
||||
>
|
||||
<?php if ($emptyOption): ?>
|
||||
<option value=""><?= e(trans($emptyOption)) ?></option>
|
||||
<?php endif ?>
|
||||
<?php foreach ($fieldOptions as $value => $option): ?>
|
||||
<?php
|
||||
if (!is_array($option)) $option = [$option];
|
||||
|
|
|
|||
|
|
@ -90,17 +90,10 @@
|
|||
}
|
||||
|
||||
var placeholder = $element.data('placeholder')
|
||||
if (placeholder)
|
||||
{
|
||||
if (placeholder) {
|
||||
extraOptions.placeholder = placeholder;
|
||||
}
|
||||
|
||||
if ($element.hasClass('select-allow-clear'))
|
||||
{
|
||||
extraOptions.allowClear = true;
|
||||
}
|
||||
|
||||
|
||||
$element.select2($.extend({}, selectOptions, extraOptions))
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -3184,6 +3184,8 @@ if($element.hasClass('select-no-dropdown')){extraOptions.selectOnClose=true
|
|||
extraOptions.closeOnSelect=false
|
||||
$element.on('select2:closing',function(){$('.select2-dropdown.select-no-dropdown:first .select2-results__option--highlighted').removeClass('select2-results__option--highlighted')
|
||||
$('.select2-dropdown.select-no-dropdown:first .select2-results__option:first').addClass('select2-results__option--highlighted')})}}
|
||||
var placeholder=$element.data('placeholder')
|
||||
if(placeholder){extraOptions.placeholder=placeholder;}
|
||||
$element.select2($.extend({},selectOptions,extraOptions))})})
|
||||
$(document).on('disable','select.custom-select',function(event,status){if($(this).data('select2')!=null){$(this).select2('enable',!status)}})})(jQuery);+function($){"use strict";var LoadIndicator=function(element,options){this.$el=$(element)
|
||||
this.options=options||{}
|
||||
|
|
|
|||
Loading…
Reference in New Issue