1
0
mirror of synced 2025-02-09 16:49:24 +03:00

add default initselection for single and multi

This commit is contained in:
vitalets 2013-01-16 22:35:24 +04:00
parent 3570ab523e
commit 88a86e5953

View File

@ -1663,19 +1663,16 @@ the specific language governing permissions and limitations under the Apache Lic
} else if ("data" in opts) {
// install default initSelection when applied to hidden input and data is local
opts.initSelection = opts.initSelection || function (element, callback) {
var data,
id = element.val();
$.each(opts.data, function(k, v){
if(id == opts.id(v)) {
data = v;
return false;
var id = element.val();
//search in data by id
opts.query({
matcher: function(term, text, el){
return equal(id, opts.id(el));
},
callback: !$.isFunction(callback) ? $.noop : function(filtered) {
callback(filtered.results.length ? filtered.results[0] : null);
}
});
if ($.isFunction(callback)) {
callback(data);
}
};
}
@ -1864,6 +1861,22 @@ the specific language governing permissions and limitations under the Apache Lic
if ($.isFunction(callback))
callback(data);
};
} else if ("data" in opts) {
// install default initSelection when applied to hidden input and data is local
opts.initSelection = opts.initSelection || function (element, callback) {
var ids = splitVal(element.val(), opts.separator);
//search in data by array of ids
opts.query({
matcher: function(term, text, el){
return $.grep(ids, function(id) {
return equal(id, opts.id(el));
}).length;
},
callback: !$.isFunction(callback) ? $.noop : function(filtered) {
callback(filtered.results);
}
});
};
}
return opts;