Skip to content

Commit

Permalink
enabled empty values for choices
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Kunitzsch committed Jun 14, 2019
1 parent 0c64e2b commit 903d1ef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Filter/Type/ChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getOptions(FilterConfigElementModel $element, FormBuilderInterfa
$options = parent::getOptions($element, $builder, false);
$options['choices'] = $this->getChoices($element);
$options['choice_translation_domain'] = false; // disable translation
$options['choices'] = array_filter($options['choices'], 'strlen'); // remove empty elements (placeholders)
// $options['choices'] = array_filter($options['choices'], 'strlen'); // remove empty elements (placeholders)

if (isset($options['attr']['placeholder'])) {
$options['attr']['data-placeholder'] = $options['attr']['placeholder'];
Expand Down
24 changes: 22 additions & 2 deletions src/Resources/npm-package/js/contao-filter-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ class FilterBundle {
document.addEventListener('filterAsyncSubmit', function(event) {
event.preventDefault();
FilterBundle.asyncSubmit(event.detail.form);
})
});

utilsBundle.event.addDynamicEventListener('click', '.mod_filter form [data-submit-on-change] input[type="radio"][value=""], .mod_filter form [data-submit-on-change] input[type="checkbox"][value=""]', function(element, event) {
FilterBundle.resetRadioAndCheckboxField(element);
});

utilsBundle.event.addDynamicEventListener('change',
'.mod_filter form[data-async] input[data-submit-on-change], .mod_filter form[data-async] [data-submit-on-change] input',
Expand Down Expand Up @@ -87,18 +91,22 @@ class FilterBundle {
}

static beforeSubmit(url, data, config) {
let form = config.form;
let form = config.form,
list = document.querySelector(form.getAttribute('data-list'));

form.setAttribute('data-submit-success', 0);
form.setAttribute('data-response', '');
form.querySelectorAll('input:not(.disabled), button[type="submit"]').forEach((elem) => {
elem.disabled = true;
});

form.classList.add('submitting');
list.classList.add('updating');
}

static afterSubmit(url, data, config) {
let form = config.form;

form.querySelectorAll('[disabled]').forEach((elem) => {
elem.disabled = false;
});
Expand Down Expand Up @@ -132,6 +140,18 @@ class FilterBundle {
}
});
}

static resetRadioAndCheckboxField(element) {
let parent = element.closest('[data-choices]'),
form = element.closest('form'),
checked = parent.querySelectorAll('input:checked');

checked.forEach((elem) => {
elem.checked = false;
});

FilterBundle.asyncSubmit(form);
}
}

export {FilterBundle};

0 comments on commit 903d1ef

Please sign in to comment.