1
0
mirror of synced 2024-11-22 13:06:08 +03:00

imrpove handling of objects in tags helper. closes #50

This commit is contained in:
Igor Vaynberg 2012-04-27 11:40:32 -07:00
parent ee6f8975a6
commit 11b0a1662c

View File

@ -286,6 +286,8 @@
// TODO javadoc
function tags(data) {
// TODO even for a function we should probably return a wrapper that does the same object/string check as
// the function for arrays. otherwise only functions that return objects are supported.
if ($.isFunction(data)) {
return data;
}
@ -295,7 +297,12 @@
return function (query) {
var t = query.term.toUpperCase(), filtered = {results: []};
$(data).each(function () {
if (t === "" || this.toUpperCase().indexOf(t) >= 0) { filtered.results.push({id: this, text: this}); }
console.log(this);
var isObject = "text" in this,
text = isObject ? this.text : this;
if (t === "" || text.toUpperCase().indexOf(t) >= 0) {
filtered.results.push(isObject ? this : {id: this, text: this});
}
});
query.callback(filtered);
};
@ -1061,7 +1068,6 @@
// TODO validate placeholder is a string if specified
if (opts.element.get(0).tagName.toLowerCase() === "select") {
// install sthe selection initializer
opts.initSelection = function (element) {
@ -1230,7 +1236,6 @@
this.addSelectedChoice(data);
if (this.select) { this.postprocessResults(); }
if (this.opts.closeOnSelect) {
this.close();
this.search.width(10);