null value for select not trigger source load

This commit is contained in:
vitalets
2012-12-28 17:01:39 +04:00
parent 94cee0731a
commit d56271c021
3 changed files with 46 additions and 14 deletions

@ -4,6 +4,7 @@ X-editable changelog
Version 1.3.1 wip 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 #53] 'name' no more appended to source defined as url (vitalets)
[enh #46] move 'img' dir outside 'css' (vitalets) [enh #46] move 'img' dir outside 'css' (vitalets)
[enh #48] fix handling of newlines in textarea input (jmfontaine) [enh #48] fix handling of newlines in textarea input (jmfontaine)

@ -35,19 +35,23 @@ List - abstract class for inputs that have source option loaded from js array or
}, },
value2html: function (value, element, display) { value2html: function (value, element, display) {
var deferred = $.Deferred(); var deferred = $.Deferred(),
this.onSourceReady(function () { success = function () {
if(typeof display === 'function') { if(typeof display === 'function') {
//custom display method //custom display method
display.call(element, value, this.sourceData); display.call(element, value, this.sourceData);
} else { } else {
this.value2htmlFinal(value, element); this.value2htmlFinal(value, element);
} }
deferred.resolve(); deferred.resolve();
}, function () { };
//do nothing with 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(); return deferred.promise();
}, },

@ -596,7 +596,34 @@ $(function () {
e.remove(); e.remove();
start(); start();
}, timeout); }, 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);
});
}); });