diff --git a/CHANGELOG.txt b/CHANGELOG.txt index fae72c5..afed417 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,7 @@ X-editable changelog Version 1.3.1 wip ---------------------------- +[enh] if new value for select is 'null' source should not load (vitalets) [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) diff --git a/src/inputs/list.js b/src/inputs/list.js index eab04c7..2cf8414 100644 --- a/src/inputs/list.js +++ b/src/inputs/list.js @@ -35,19 +35,23 @@ List - abstract class for inputs that have source option loaded from js array or }, value2html: function (value, element, display) { - var deferred = $.Deferred(); - this.onSourceReady(function () { - if(typeof display === 'function') { - //custom display method - display.call(element, value, this.sourceData); - } else { - this.value2htmlFinal(value, element); - } - deferred.resolve(); - }, function () { - //do nothing with element - deferred.resolve(); - }); + var deferred = $.Deferred(), + success = function () { + if(typeof display === 'function') { + //custom display method + display.call(element, value, this.sourceData); + } else { + this.value2htmlFinal(value, element); + } + deferred.resolve(); + }; + + //for null value just call success without loading source + if(value === null) { + success.call(this); + } else { + this.onSourceReady(success, function () { deferred.resolve(); }); + } return deferred.promise(); }, diff --git a/test/unit/select.js b/test/unit/select.js index 65c43e5..138fdf9 100644 --- a/test/unit/select.js +++ b/test/unit/select.js @@ -596,7 +596,34 @@ $(function () { e.remove(); start(); }, timeout); - }) + }); + + + asyncTest("set value to null should not trigger source load", function () { + var req = 0; + $.mockjax({ + url: 'groups-null.php', + response: function() { + req++; + } + }); + + var e = $('<a href="#" data-type="select" data-pk="1" data-name="name1" data-value="1" data-url="post.php" data-source="groups-null.php">11</a>').appendTo(fx).editable(), + d = e.data('editable'); + + e.editable('setValue', null); + + setTimeout(function() { + equal(req, 0, 'no request'); + equal(e.text(), d.options.emptytext, 'text correct'); + equal(d.value, null, 'value correct'); + + e.remove(); + start(); + }, timeout); + + }); + });