Commit 2b06b169 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'search-field-ignores' into 'master'

Intercept issues search form submit to preserve filters.

## What does this MR do?

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/896 by intercepting manual search form submission and redirecting it to use existing logic (now factored out into `executeSearch`).  

## Why was this MR needed?

Manual form submission (keying in 'enter') in issues search did not preserve applied filters. 

## What are the relevant issue numbers?

https://gitlab.com/gitlab-org/gitlab-ce/issues/896

See merge request !6054
parents 5fdc1f11 726071e6
...@@ -17,6 +17,7 @@ v 8.12.0 (unreleased) ...@@ -17,6 +17,7 @@ v 8.12.0 (unreleased)
- Fix note form hint showing slash commands supported for commits. - Fix note form hint showing slash commands supported for commits.
- Make push events have equal vertical spacing. - Make push events have equal vertical spacing.
- API: Ensure invitees are not returned in Members API. - API: Ensure invitees are not returned in Members API.
- Preserve applied filters on issues search.
- Add two-factor recovery endpoint to internal API !5510 - Add two-factor recovery endpoint to internal API !5510
- Pass the "Remember me" value to the U2F authentication form - Pass the "Remember me" value to the U2F authentication form
- Display stages in valid order in stages dropdown on build page - Display stages in valid order in stages dropdown on build page
......
...@@ -15,24 +15,31 @@ ...@@ -15,24 +15,31 @@
return Issuable.labelRow = _.template('<% _.each(labels, function(label){ %> <span class="label-row btn-group" role="group" aria-label="<%- label.title %>" style="color: <%- label.text_color %>;"> <a href="#" class="btn btn-transparent has-tooltip" style="background-color: <%- label.color %>;" title="<%- label.description %>" data-container="body"> <%- label.title %> </a> <button type="button" class="btn btn-transparent label-remove js-label-filter-remove" style="background-color: <%- label.color %>;" data-label="<%- label.title %>"> <i class="fa fa-times"></i> </button> </span> <% }); %>'); return Issuable.labelRow = _.template('<% _.each(labels, function(label){ %> <span class="label-row btn-group" role="group" aria-label="<%- label.title %>" style="color: <%- label.text_color %>;"> <a href="#" class="btn btn-transparent has-tooltip" style="background-color: <%- label.color %>;" title="<%- label.description %>" data-container="body"> <%- label.title %> </a> <button type="button" class="btn btn-transparent label-remove js-label-filter-remove" style="background-color: <%- label.color %>;" data-label="<%- label.title %>"> <i class="fa fa-times"></i> </button> </span> <% }); %>');
}, },
initSearch: function() { initSearch: function() {
this.timer = null; // `immediate` param set to false debounces on the `trailing` edge, lets user finish typing
return $('#issuable_search').off('keyup').on('keyup', function() { const debouncedExecSearch = _.debounce(Issuable.executeSearch, 500, false);
clearTimeout(this.timer);
return this.timer = setTimeout(function() { $('#issuable_search').off('keyup').on('keyup', debouncedExecSearch);
var $form, $input, $search;
$search = $('#issuable_search'); // ensures existing filters are preserved when manually submitted
$form = $('.js-filter-form'); $('#issue_search_form').on('submit', (e) => {
$input = $("input[name='" + ($search.attr('name')) + "']", $form); e.preventDefault();
if ($input.length === 0) { debouncedExecSearch(e);
$form.append("<input type='hidden' name='" + ($search.attr('name')) + "' value='" + (_.escape($search.val())) + "'/>"); });
},
executeSearch: function(e) {
const $search = $('#issuable_search');
const $searchName = $search.attr('name');
const $searchValue = $search.val();
const $filtersForm = $('.js-filter-form');
const $input = $(`input[name='${$searchName}']`, $filtersForm);
if (!$input.length) {
$filtersForm.append(`<input type='hidden' name='${$searchName}' value='${_.escape($searchValue)}'/>`);
} else { } else {
$input.val($search.val()); $input.val($searchValue);
}
if ($search.val() !== '') {
return Issuable.filterResults($form);
} }
}, 500);
}); Issuable.filterResults($filtersForm);
}, },
initLabelFilterRemove: function() { initLabelFilterRemove: function() {
return $(document).off('click', '.js-label-filter-remove').on('click', '.js-label-filter-remove', function(e) { return $(document).off('click', '.js-label-filter-remove').on('click', '.js-label-filter-remove', function(e) {
......
Markdown is supported
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