Commit 5fdc1f11 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'hotfix-gl-dropdown-field-undefined' into 'master'

Fixes protected branches not removing active item

## What does this MR do?

Fixes an problem where protected branches weren't getting their active item removed on a second click because they dont have a field value.

## Why was this MR needed?

Protected branches could not have their clicked items removed once clicked.

See merge request !6440
parents 2450625b 2c4fe74b
...@@ -608,27 +608,28 @@ ...@@ -608,27 +608,28 @@
} }
} }
field = []; field = [];
fieldName = typeof this.options.fieldName === 'function' ? this.options.fieldName(selectedObject) : this.options.fieldName;
value = this.options.id ? this.options.id(selectedObject, el) : selectedObject.id; value = this.options.id ? this.options.id(selectedObject, el) : selectedObject.id;
if (isInput) { if (isInput) {
field = $(this.el); field = $(this.el);
} else if(value) { } else if(value) {
field = this.dropdown.parent().find("input[name='" + fieldName + "'][value='" + value.toString().replace(/'/g, '\\\'') + "']"); field = this.dropdown.parent().find("input[name='" + fieldName + "'][value='" + value.toString().replace(/'/g, '\\\'') + "']");
} }
if (field.length && el.hasClass(ACTIVE_CLASS)) { if (el.hasClass(ACTIVE_CLASS)) {
el.removeClass(ACTIVE_CLASS); el.removeClass(ACTIVE_CLASS);
if (field && field.length) {
if (isInput) { if (isInput) {
field.val(''); field.val('');
} else { } else {
field.remove(); field.remove();
} }
}
} else if (el.hasClass(INDETERMINATE_CLASS)) { } else if (el.hasClass(INDETERMINATE_CLASS)) {
el.addClass(ACTIVE_CLASS); el.addClass(ACTIVE_CLASS);
el.removeClass(INDETERMINATE_CLASS); el.removeClass(INDETERMINATE_CLASS);
if (field.length && value == null) { if (field && field.length && value == null) {
field.remove(); field.remove();
} }
if (!field.length && fieldName) { if ((!field || !field.length) && fieldName) {
this.addInput(fieldName, value, selectedObject); this.addInput(fieldName, value, selectedObject);
} }
} else { } else {
...@@ -638,15 +639,15 @@ ...@@ -638,15 +639,15 @@
this.dropdown.parent().find("input[name='" + fieldName + "']").remove(); this.dropdown.parent().find("input[name='" + fieldName + "']").remove();
} }
} }
if (field.length && value == null) { if (field && field.length && value == null) {
field.remove(); field.remove();
} }
// Toggle active class for the tick mark // Toggle active class for the tick mark
el.addClass(ACTIVE_CLASS); el.addClass(ACTIVE_CLASS);
if (value != null) { if (value != null) {
if (!field.length && fieldName) { if ((!field || !field.length) && fieldName) {
this.addInput(fieldName, value, selectedObject); this.addInput(fieldName, value, selectedObject);
} else if (field.length) { } else if (field && field.length) {
field.val(value).trigger('change'); field.val(value).trigger('change');
} }
} }
......
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