convert source from x-editable format to select2 format
This commit is contained in:
parent
4d1100d4b4
commit
502151b9dc
22
src/inputs/select2/select2.js
vendored
22
src/inputs/select2/select2.js
vendored
@ -63,9 +63,9 @@ $(function(){
|
|||||||
}
|
}
|
||||||
options.select2.ajax.url = source;
|
options.select2.ajax.url = source;
|
||||||
} else {
|
} else {
|
||||||
//todo: possible convert x-editable source to select2 source format
|
//check format and convert x-editable format to select2 format (if needed)
|
||||||
options.select2.data = source;
|
this.sourceData = this.convertSource(source);
|
||||||
this.sourceData = source;
|
options.select2.data = this.sourceData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,6 +186,22 @@ $(function(){
|
|||||||
$(this).closest('form').submit();
|
$(this).closest('form').submit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
Converts source from x-editable format: {value: 1, text: "1"} to
|
||||||
|
select2 format: {id: 1, text: "1"}
|
||||||
|
*/
|
||||||
|
convertSource: function(source) {
|
||||||
|
if($.isArray(source) && source.length && source[0].value !== undefined) {
|
||||||
|
for(var i = 0; i<source.length; i++) {
|
||||||
|
if(source[i].value !== undefined) {
|
||||||
|
source[i].id = source[i].value;
|
||||||
|
delete source[i].value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -142,9 +142,9 @@ $(function () {
|
|||||||
}, timeout);
|
}, timeout);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("setValue (local)", function () {
|
test("setValue (local) + x-editable source", function () {
|
||||||
var e = $('<a href="#" data-type="select2" data-name="select2" data-value="1">test2</a>').appendTo('#qunit-fixture').editable({
|
var e = $('<a href="#" data-type="select2" data-name="select2" data-value="1">test2</a>').appendTo('#qunit-fixture').editable({
|
||||||
source: [{id: 1, text: 'text1'}, {id: 2, text: 'text2'}, {id: 3, text: 'text3'}]
|
source: [{value: 1, text: 'text1'}, {value: 2, text: 'text2'}, {value: 3, text: 'text3'}]
|
||||||
});
|
});
|
||||||
|
|
||||||
//autotext
|
//autotext
|
||||||
|
Loading…
x
Reference in New Issue
Block a user