diff options
author | Rémy Coutable <remy@rymai.me> | 2016-09-22 12:52:54 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-09-22 15:48:30 +0200 |
commit | 8bb964c5f7cd8808033fb5b15c2a00f249b44d3d (patch) | |
tree | ff56327dc101a3dd70323e543bd6f6fc8607c610 | |
parent | 8c273ccda22501f65f69f431283e5320d5433abb (diff) | |
download | gitlab-ce-8bb964c5f7cd8808033fb5b15c2a00f249b44d3d.tar.gz |
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
-rw-r--r-- | app/assets/javascripts/gl_dropdown.js | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/app/assets/javascripts/gl_dropdown.js b/app/assets/javascripts/gl_dropdown.js index c05cda25bbd..1b6db641200 100644 --- a/app/assets/javascripts/gl_dropdown.js +++ b/app/assets/javascripts/gl_dropdown.js @@ -608,27 +608,28 @@ } } 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; if (isInput) { field = $(this.el); } else if(value) { 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); - if (isInput) { - field.val(''); - } else { - field.remove(); + if (field && field.length) { + if (isInput) { + field.val(''); + } else { + field.remove(); + } } } else if (el.hasClass(INDETERMINATE_CLASS)) { el.addClass(ACTIVE_CLASS); el.removeClass(INDETERMINATE_CLASS); - if (field.length && value == null) { + if (field && field.length && value == null) { field.remove(); } - if (!field.length && fieldName) { + if ((!field || !field.length) && fieldName) { this.addInput(fieldName, value, selectedObject); } } else { @@ -638,15 +639,15 @@ this.dropdown.parent().find("input[name='" + fieldName + "']").remove(); } } - if (field.length && value == null) { + if (field && field.length && value == null) { field.remove(); } // Toggle active class for the tick mark el.addClass(ACTIVE_CLASS); if (value != null) { - if (!field.length && fieldName) { + if ((!field || !field.length) && fieldName) { this.addInput(fieldName, value, selectedObject); - } else if (field.length) { + } else if (field && field.length) { field.val(value).trigger('change'); } } @@ -796,4 +797,4 @@ }); }; -}).call(this);
\ No newline at end of file +}).call(this); |