diff --git a/CHANGELOG.txt b/CHANGELOG.txt index aeb236c..fae72c5 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,7 @@ X-editable changelog Version 1.3.1 wip ---------------------------- +[enh #53] 'name' no more appended to source defined as url (vitalets) [enh #46] move 'img' dir outside 'css' (vitalets) [enh #48] fix handling of newlines in textarea input (jmfontaine) [enh #47] set select source to function (brianchance) diff --git a/src/inputs/list.js b/src/inputs/list.js index 90b65c3..eab04c7 100644 --- a/src/inputs/list.js +++ b/src/inputs/list.js @@ -73,7 +73,7 @@ List - abstract class for inputs that have source option loaded from js array or if (typeof this.options.source === 'string') { //try to get from cache if(this.options.sourceCache) { - var cacheID = this.options.source + (this.options.name ? '-' + this.options.name : ''), + var cacheID = this.options.source, cache; if (!$(document).data(cacheID)) { @@ -84,11 +84,13 @@ List - abstract class for inputs that have source option loaded from js array or //check for cached data if (cache.loading === false && cache.sourceData) { //take source from cache this.sourceData = cache.sourceData; + this.doPrepend(); success.call(this); return; } else if (cache.loading === true) { //cache is loading, put callback in stack to be called later cache.callbacks.push($.proxy(function () { this.sourceData = cache.sourceData; + this.doPrepend(); success.call(this); }, this)); @@ -107,7 +109,6 @@ List - abstract class for inputs that have source option loaded from js array or url: this.options.source, type: 'get', cache: false, - data: this.options.name ? {name: this.options.name} : {}, dataType: 'json', success: $.proxy(function (data) { if(cache) { @@ -115,17 +116,19 @@ List - abstract class for inputs that have source option loaded from js array or } this.sourceData = this.makeArray(data); if($.isArray(this.sourceData)) { - this.doPrepend(); - success.call(this); if(cache) { //store result in cache cache.sourceData = this.sourceData; - $.each(cache.callbacks, function () { this.call(); }); //run success callbacks for other fields + //run success callbacks for other fields waiting for this source + $.each(cache.callbacks, function () { this.call(); }); } + this.doPrepend(); + success.call(this); } else { error.call(this); if(cache) { - $.each(cache.err_callbacks, function () { this.call(); }); //run error callbacks for other fields + //run error callbacks for other fields waiting for this source + $.each(cache.err_callbacks, function () { this.call(); }); } } }, this), diff --git a/test/unit/select.js b/test/unit/select.js index 15c5eb7..65c43e5 100644 --- a/test/unit/select.js +++ b/test/unit/select.js @@ -19,7 +19,10 @@ $(function () { }) asyncTest("load options from server", function () { - var e = $('<a href="#" data-type="select" data-name="load-srv" data-value="2" data-source="groups.php">customer</a>').appendTo(fx).editable(); + var e = $('<a href="#" data-type="select" data-name="load-srv" data-value="2" data-source="groups.php">customer</a>').appendTo(fx).editable({ + //need to disable cache to force request + sourceCache: false + }); e.click(); var p = tip(e); @@ -265,7 +268,7 @@ $(function () { asyncTest("cache request for same selects", function () { //clear cache - $(document).removeData('groups.php-name1'); + $(document).removeData('groups.php'); var e = $('<a href="#" data-type="select" data-pk="1" data-name="name1" data-value="2" data-url="post.php" data-source="groups-cache.php">customer</a>').appendTo(fx).editable(), e1 = $('<a href="#" data-type="select" data-pk="1" id="name1" data-value="2" data-url="post.php" data-source="groups-cache.php">customer</a>').appendTo(fx).editable(), @@ -314,7 +317,7 @@ $(function () { expect(4); //clear cache - $(document).removeData('groups-cache-sim.php-name1'); + $(document).removeData('groups-cache-sim.php'); var req = 0; $.mockjax({ @@ -348,7 +351,7 @@ $(function () { expect(4); //clear cache - $(document).removeData('groups-cache-sim-err.php-name1'); + $(document).removeData('groups-cache-sim-err.php'); var req = 0; $.mockjax({