Skip to content

Commit

Permalink
Remove "allowClear" and tidy up #2459
Browse files Browse the repository at this point in the history
Allow clear is not necessary, equivalent of allowClear false is "placeholder" and allowClear true is "emptyOption".
  • Loading branch information
daftspunk committed Nov 6, 2016
1 parent 1ee0250 commit 4aca2d4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 17 deletions.
2 changes: 0 additions & 2 deletions modules/backend/formwidgets/Relation.php
Expand Up @@ -112,8 +112,6 @@ protected function makeRenderFormField()
$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))) {
Expand Down
12 changes: 5 additions & 7 deletions modules/backend/widgets/form/partials/_field_dropdown.htm
@@ -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): ?>
Expand All @@ -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];
Expand Down
9 changes: 1 addition & 8 deletions modules/system/assets/ui/js/select.js
Expand Up @@ -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))
})
})
Expand Down
2 changes: 2 additions & 0 deletions modules/system/assets/ui/storm-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4aca2d4

Please sign in to comment.