Commit 0d3a9a6d authored by Alfredo Sumaran's avatar Alfredo Sumaran

make input name to be a function

parent 72503666
...@@ -470,7 +470,8 @@ ...@@ -470,7 +470,8 @@
} else { } else {
if (!selected) { if (!selected) {
value = this.options.id ? this.options.id(data) : data.id; value = this.options.id ? this.options.id(data) : data.id;
fieldName = this.options.fieldName; fieldName = _.isFunction(this.options.fieldName) ? this.options.fieldName() : this.options.fieldName;
field = this.dropdown.parent().find("input[name='" + fieldName + "'][value='" + value + "']"); field = this.dropdown.parent().find("input[name='" + fieldName + "'][value='" + value + "']");
if (field.length) { if (field.length) {
selected = true; selected = true;
...@@ -533,7 +534,6 @@ ...@@ -533,7 +534,6 @@
GitLabDropdown.prototype.rowClicked = function(el) { GitLabDropdown.prototype.rowClicked = function(el) {
var field, fieldName, groupName, isInput, selectedIndex, selectedObject, value; var field, fieldName, groupName, isInput, selectedIndex, selectedObject, value;
fieldName = this.options.fieldName;
isInput = $(this.el).is('input'); isInput = $(this.el).is('input');
if (this.renderedData) { if (this.renderedData) {
groupName = el.data('group'); groupName = el.data('group');
...@@ -545,6 +545,7 @@ ...@@ -545,6 +545,7 @@
selectedObject = this.renderedData[selectedIndex]; selectedObject = this.renderedData[selectedIndex];
} }
} }
fieldName = _.isFunction(this.options.fieldName) ? 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);
...@@ -559,10 +560,9 @@ ...@@ -559,10 +560,9 @@
field.remove(); field.remove();
} }
if (this.options.toggleLabel) { if (this.options.toggleLabel) {
return this.updateLabel(selectedObject, el, this); this.updateLabel(selectedObject, el, this);
} else {
return selectedObject;
} }
return selectedObject;
} 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);
...@@ -570,7 +570,7 @@ ...@@ -570,7 +570,7 @@
field.remove(); field.remove();
} }
if (!field.length && fieldName) { if (!field.length && fieldName) {
this.addInput(fieldName, value); this.addInput(fieldName, value, selectedObject);
} }
return selectedObject; return selectedObject;
} else { } else {
...@@ -589,7 +589,7 @@ ...@@ -589,7 +589,7 @@
} }
if (value != null) { if (value != null) {
if (!field.length && fieldName) { if (!field.length && fieldName) {
this.addInput(fieldName, value); this.addInput(fieldName, value, selectedObject);
} else { } else {
field.val(value).trigger('change'); field.val(value).trigger('change');
} }
...@@ -598,12 +598,15 @@ ...@@ -598,12 +598,15 @@
} }
}; };
GitLabDropdown.prototype.addInput = function(fieldName, value) { GitLabDropdown.prototype.addInput = function(fieldName, value, selectedObject) {
var $input; var $input;
$input = $('<input>').attr('type', 'hidden').attr('name', fieldName).val(value); $input = $('<input>').attr('type', 'hidden').attr('name', fieldName).val(value);
if (this.options.inputId != null) { if (this.options.inputId != null) {
$input.attr('id', this.options.inputId); $input.attr('id', this.options.inputId);
} }
if (selectedObject.type) {
$input.attr('data-type', selectedObject.type);
}
return this.dropdown.before($input); return this.dropdown.before($input);
}; };
......
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