Commit 767262ac authored by Fatih Acet's avatar Fatih Acet

Merge branch '25312-search-input-cmd-click-issue' into 'master'

Prevent removal of input that is the parent dropdown element

Closes #25312

See merge request !8397
parents 637894de 8010de30
...@@ -651,18 +651,14 @@ ...@@ -651,18 +651,14 @@
isMarking = false; isMarking = false;
el.removeClass(ACTIVE_CLASS); el.removeClass(ACTIVE_CLASS);
if (field && field.length) { if (field && field.length) {
if (isInput) { this.clearField(field, isInput);
field.val('');
} else {
field.remove();
}
} }
} else if (el.hasClass(INDETERMINATE_CLASS)) { } else if (el.hasClass(INDETERMINATE_CLASS)) {
isMarking = true; isMarking = true;
el.addClass(ACTIVE_CLASS); el.addClass(ACTIVE_CLASS);
el.removeClass(INDETERMINATE_CLASS); el.removeClass(INDETERMINATE_CLASS);
if (field && field.length && value == null) { if (field && field.length && value == null) {
field.remove(); this.clearField(field, isInput);
} }
if ((!field || !field.length) && fieldName) { if ((!field || !field.length) && fieldName) {
this.addInput(fieldName, value, selectedObject); this.addInput(fieldName, value, selectedObject);
...@@ -676,7 +672,7 @@ ...@@ -676,7 +672,7 @@
} }
} }
if (field && field.length && value == null) { if (field && field.length && value == null) {
field.remove(); this.clearField(field, isInput);
} }
// Toggle active class for the tick mark // Toggle active class for the tick mark
el.addClass(ACTIVE_CLASS); el.addClass(ACTIVE_CLASS);
...@@ -826,6 +822,10 @@ ...@@ -826,6 +822,10 @@
return $(this.el).find(".dropdown-toggle-text").text(this.options.toggleLabel(selected, el, instance)); return $(this.el).find(".dropdown-toggle-text").text(this.options.toggleLabel(selected, el, instance));
}; };
GitLabDropdown.prototype.clearField = function(field, isInput) {
return isInput ? field.val('') : field.remove();
};
return GitLabDropdown; return GitLabDropdown;
})(); })();
......
...@@ -69,12 +69,17 @@ ...@@ -69,12 +69,17 @@
search: { search: {
fields: ['text'] fields: ['text']
}, },
id: this.getSearchText,
data: this.getData.bind(this), data: this.getData.bind(this),
selectable: true, selectable: true,
clicked: this.onClick.bind(this) clicked: this.onClick.bind(this)
}); });
} }
getSearchText(selectedObject, el) {
return selectedObject.id ? selectedObject.text : '';
}
getData(term, callback) { getData(term, callback) {
var _this, contents, jqXHR; var _this, contents, jqXHR;
_this = this; _this = this;
...@@ -364,7 +369,7 @@ ...@@ -364,7 +369,7 @@
onClick(item, $el, e) { onClick(item, $el, e) {
if (location.pathname.indexOf(item.url) !== -1) { if (location.pathname.indexOf(item.url) !== -1) {
e.preventDefault(); if (!e.metaKey) e.preventDefault();
if (!this.badgePresent) { if (!this.badgePresent) {
if (item.category === 'Projects') { if (item.category === 'Projects') {
this.projectInputEl.val(item.id); this.projectInputEl.val(item.id);
......
---
title: Prevent removal of input fields if it is the parent dropdown element
merge_request: 8397
author:
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