diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/gl_dropdown.js | 10 | ||||
-rw-r--r-- | app/assets/javascripts/project.js | 2 | ||||
-rw-r--r-- | app/assets/javascripts/repo/helpers/get_safe_branch_name_helper.js | 6 |
3 files changed, 14 insertions, 4 deletions
diff --git a/app/assets/javascripts/gl_dropdown.js b/app/assets/javascripts/gl_dropdown.js index 6eaff81f7b7..7c9bb47ac34 100644 --- a/app/assets/javascripts/gl_dropdown.js +++ b/app/assets/javascripts/gl_dropdown.js @@ -43,8 +43,10 @@ const GitLabDropdownInput = (function() { GitLabDropdownInput.prototype.setToggleText = function(e) { var val = e.currentTarget.value || this.options.inputFieldName; - val = val.split(' ').join('-') // replaces space with dash - .replace(/[^a-zA-Z0-9-/]/g, ''); // replace non alphanumeric + if (this.options.updateLabel) { + val = typeof this.options.updateLabel === 'function' ? this.options.updateLabel(val) : this.options.updateLabel; + } + this.cb(this.options.fieldName, val, {}, true); this.input.closest('.dropdown') .find('.dropdown-toggle-text') @@ -953,9 +955,9 @@ GitLabDropdown = (function() { } let toggleText = this.options.toggleLabel(selected, el, instance); + // Option to override or process the dropdown label text if (this.options.updateLabel) { - // Option to override the dropdown label text - toggleText = this.options.updateLabel; + toggleText = typeof this.options.updateLabel === 'function' ? this.options.updateLabel(toggleText) : this.options.updateLabel; } return $(this.el).find(".dropdown-toggle-text").text(toggleText); diff --git a/app/assets/javascripts/project.js b/app/assets/javascripts/project.js index d7e3ab42f00..54b434e27bf 100644 --- a/app/assets/javascripts/project.js +++ b/app/assets/javascripts/project.js @@ -2,6 +2,7 @@ /* global ProjectSelect */ import Cookies from 'js-cookie'; +import getSafeBranchName from './repo/helpers/get_safe_branch_name_helper'; (function() { this.Project = (function() { @@ -119,6 +120,7 @@ import Cookies from 'js-cookie'; toggleLabel: function(obj, $el) { return $el.text().trim(); }, + updateLabel: getSafeBranchName, clicked: function(options) { const { e } = options; e.preventDefault(); diff --git a/app/assets/javascripts/repo/helpers/get_safe_branch_name_helper.js b/app/assets/javascripts/repo/helpers/get_safe_branch_name_helper.js new file mode 100644 index 00000000000..8c617631733 --- /dev/null +++ b/app/assets/javascripts/repo/helpers/get_safe_branch_name_helper.js @@ -0,0 +1,6 @@ +function getSafeBranchName(text) { + return text.split(' ').join('-') // replaces space with dash + .replace(/[^a-zA-Z0-9-/]/g, ''); // replace non alphanumeric +} + +export default getSafeBranchName; |