Commit 3e6a1e6c authored by tostinni's avatar tostinni Committed by Rick Hawkins
Browse files

Issue #2921744 by tostinni, oxyc, trebormc, Kushal Bansal, rlhawk: Text fields...

Issue #2921744 by tostinni, oxyc, trebormc, Kushal Bansal, rlhawk: Text fields are auto-submitted before user have finished typing keywords
parent b3c550ee
......@@ -16,6 +16,7 @@ auto_submit:
- core/drupal
- core/jquery.once
- core/drupal.debounce
- core/drupalSettings
select_all_none:
version: 3.x
js:
......
......@@ -15,6 +15,9 @@ better_exposed_filters.general:
autosubmit_exclude_textfield:
type: boolean
label: 'Exclude Textfield'
autosubmit_textfield_delay:
type: integer
label: 'Delay for textfield autosubmit'
autosubmit_hide:
type: boolean
label: 'Hide submit button'
......
......@@ -81,13 +81,23 @@
// Use debounce to prevent excessive submits on text field changes.
// Navigation key presses are ignored.
else if ($target.is(':text:not(.hasDatepicker), textarea') && $.inArray(e.keyCode, ignoredKeyCodes) === -1) {
Drupal.debounce(triggerSubmit, 500)($target);
return;
}
// Only trigger submit if a change was the trigger (no keyup).
else if (e.type === 'change') {
triggerSubmit($target);
}
});
$(selectors, context).addBack(selectors).find('input:text:not(.hasDatepicker), textarea').once('bef-auto-submit-text').on('change keyup keypress', Drupal.debounce(function (e) {
var $target = $(e.target);
// Don't submit on changes to excluded elements or a submit element.
if ($target.is('[data-bef-auto-submit-exclude], :submit')) {
return true;
}
triggerSubmit($target);
}, drupalSettings.data.better_exposed_filters.autosubmitTextfieldDelay));
}
}
......
......@@ -100,6 +100,19 @@ class BetterExposedFilters extends InputRequired {
),
);
$bef_options['general']['autosubmit_textfield_delay'] = array(
'#type' => 'textfield',
'#title' => $this->t('Delay for textfield autosubmit'),
'#description' => $this->t('Configure a delay in ms before triggering autosubmit on textfields.'),
'#default_value' => $existing['general']['autosubmit_textfield_delay'],
'#states' => array(
'visible' => array(
':input[name="exposed_form_options[bef][general][autosubmit]"]' => array('checked' => TRUE),
':input[name="exposed_form_options[bef][general][autosubmit_exclude_textfield]"]' => array('checked' => FALSE),
),
),
);
$bef_options['general']['autosubmit_hide'] = array(
'#type' => 'checkbox',
'#title' => $this->t('Hide submit button'),
......@@ -669,6 +682,9 @@ Title Desc|Z -> A</pre> Leave the replacement text blank to remove an option alt
$form = array_merge_recursive($form, array('#attributes' => array('data-bef-auto-submit-full-form' => '')));
$form['actions']['submit']['#attributes']['data-bef-auto-submit-click'] = '';
$form['#attached']['library'][] = 'better_exposed_filters/auto_submit';
$form['#attached']['drupalSettings']['data']['better_exposed_filters'] = [
'autosubmitTextfieldDelay' => $settings['general']['autosubmit_textfield_delay'],
];
if (!empty($settings['general']['autosubmit_exclude_textfield'])) {
foreach ($form as &$element) {
......@@ -1544,6 +1560,7 @@ Title Desc|Z -> A</pre> Leave the replacement text blank to remove an option alt
'secondary_label' => $this->t('Advanced options'),
'autosubmit' => FALSE,
'autosubmit_exclude_textfield' => FALSE,
'autosubmit_textfield_delay' => 500,
'autosubmit_hide' => FALSE,
),
'sort' => array(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment