make input name to be a function
This commit is contained in:
parent
725036669c
commit
0d3a9a6d31
1 changed files with 11 additions and 8 deletions
|
@ -470,7 +470,8 @@
|
|||
} else {
|
||||
if (!selected) {
|
||||
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 + "']");
|
||||
if (field.length) {
|
||||
selected = true;
|
||||
|
@ -533,7 +534,6 @@
|
|||
|
||||
GitLabDropdown.prototype.rowClicked = function(el) {
|
||||
var field, fieldName, groupName, isInput, selectedIndex, selectedObject, value;
|
||||
fieldName = this.options.fieldName;
|
||||
isInput = $(this.el).is('input');
|
||||
if (this.renderedData) {
|
||||
groupName = el.data('group');
|
||||
|
@ -545,6 +545,7 @@
|
|||
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;
|
||||
if (isInput) {
|
||||
field = $(this.el);
|
||||
|
@ -559,10 +560,9 @@
|
|||
field.remove();
|
||||
}
|
||||
if (this.options.toggleLabel) {
|
||||
return this.updateLabel(selectedObject, el, this);
|
||||
} else {
|
||||
return selectedObject;
|
||||
this.updateLabel(selectedObject, el, this);
|
||||
}
|
||||
return selectedObject;
|
||||
} else if (el.hasClass(INDETERMINATE_CLASS)) {
|
||||
el.addClass(ACTIVE_CLASS);
|
||||
el.removeClass(INDETERMINATE_CLASS);
|
||||
|
@ -570,7 +570,7 @@
|
|||
field.remove();
|
||||
}
|
||||
if (!field.length && fieldName) {
|
||||
this.addInput(fieldName, value);
|
||||
this.addInput(fieldName, value, selectedObject);
|
||||
}
|
||||
return selectedObject;
|
||||
} else {
|
||||
|
@ -589,7 +589,7 @@
|
|||
}
|
||||
if (value != null) {
|
||||
if (!field.length && fieldName) {
|
||||
this.addInput(fieldName, value);
|
||||
this.addInput(fieldName, value, selectedObject);
|
||||
} else {
|
||||
field.val(value).trigger('change');
|
||||
}
|
||||
|
@ -598,12 +598,15 @@
|
|||
}
|
||||
};
|
||||
|
||||
GitLabDropdown.prototype.addInput = function(fieldName, value) {
|
||||
GitLabDropdown.prototype.addInput = function(fieldName, value, selectedObject) {
|
||||
var $input;
|
||||
$input = $('<input>').attr('type', 'hidden').attr('name', fieldName).val(value);
|
||||
if (this.options.inputId != null) {
|
||||
$input.attr('id', this.options.inputId);
|
||||
}
|
||||
if (selectedObject.type) {
|
||||
$input.attr('data-type', selectedObject.type);
|
||||
}
|
||||
return this.dropdown.before($input);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue