set select source to function

This commit is contained in:
vitalets
2012-12-28 14:28:18 +04:00
parent ffa133b2fb
commit 96a8eba12d
3 changed files with 39 additions and 16 deletions

@ -4,6 +4,7 @@ X-editable changelog
Version 1.3.1 wip Version 1.3.1 wip
---------------------------- ----------------------------
[enh #47] set select source to function (brianchance)
[bug] fix inline container move on next line in IE7 (vitalets) [bug] fix inline container move on next line in IE7 (vitalets)

@ -139,10 +139,12 @@ List - abstract class for inputs that have source option loaded from js array or
}, this) }, this)
}); });
} else { //options as json/array/function } else { //options as json/array/function
if (typeof this.options.source === 'function') if (typeof this.options.source === 'function') {
this.sourceData = this.makeArray(this.options.source()); this.sourceData = this.makeArray(this.options.source());
else } else {
this.sourceData = this.makeArray(this.options.source); this.sourceData = this.makeArray(this.options.source);
}
if($.isArray(this.sourceData)) { if($.isArray(this.sourceData)) {
this.doPrepend(); this.doPrepend();
success.call(this); success.call(this);
@ -163,11 +165,12 @@ List - abstract class for inputs that have source option loaded from js array or
if (typeof this.options.prepend === 'string') { if (typeof this.options.prepend === 'string') {
this.options.prepend = {'': this.options.prepend}; this.options.prepend = {'': this.options.prepend};
} }
if (typeof this.options.prepend === 'function') if (typeof this.options.prepend === 'function') {
this.prependData = this.makeArray(this.options.prepend()); this.prependData = this.makeArray(this.options.prepend());
else } else {
this.prependData = this.makeArray(this.options.prepend); this.prependData = this.makeArray(this.options.prepend);
} }
}
if($.isArray(this.prependData) && $.isArray(this.sourceData)) { if($.isArray(this.prependData) && $.isArray(this.sourceData)) {
this.sourceData = this.prependData.concat(this.sourceData); this.sourceData = this.prependData.concat(this.sourceData);

@ -38,7 +38,7 @@ $(function () {
e.remove(); e.remove();
start(); start();
}, timeout); }, timeout);
}) });
test("load options from json", function () { test("load options from json", function () {
var e = $('<a href="#" data-type="select" data-value="2" data-url="post.php">customer</a>').appendTo('#qunit-fixture').editable({ var e = $('<a href="#" data-type="select" data-value="2" data-url="post.php">customer</a>').appendTo('#qunit-fixture').editable({
@ -92,7 +92,26 @@ $(function () {
equal(p.find('select').val(), 'x', 'selected value correct') equal(p.find('select').val(), 'x', 'selected value correct')
p.find('button[type=button]').click(); p.find('button[type=button]').click();
ok(!p.is(':visible'), 'popover was removed'); ok(!p.is(':visible'), 'popover was removed');
}) });
test("load options from function", function () {
var e = $('<a href="#" data-type="select" data-value="2" data-url="post.php">customer</a>').appendTo('#qunit-fixture').editable({
pk: 1,
prepend: 'prepend',
source: function() {
return groups;
}
});
e.click()
var p = tip(e);
ok(p.is(':visible'), 'popover visible');
ok(p.find('select').length, 'select exists');
equal(p.find('select').find('option').length, size+1, 'options loaded');
equal(p.find('select').val(), e.data('editable').value, 'selected value correct') ;
p.find('button[type=button]').click();
ok(!p.is(':visible'), 'popover was removed');
});
test("load options from html (single quotes)", function () { test("load options from html (single quotes)", function () {
var e = $('<a href="#" data-type="select" data-value="M" data-source=\'{"L":"Low", "": "None", "M": "Medium", "H": "High"}\'>customer</a>').appendTo('#qunit-fixture').editable({ var e = $('<a href="#" data-type="select" data-value="M" data-source=\'{"L":"Low", "": "None", "M": "Medium", "H": "High"}\'>customer</a>').appendTo('#qunit-fixture').editable({