set autotext = always if display is function

This commit is contained in:
vitalets 2013-06-13 10:36:41 +04:00
parent 655aeebdc2
commit 79c06725ba
4 changed files with 25 additions and 8 deletions

@ -3,8 +3,9 @@ X-editable changelog
Version 1.4.5 wip
----------------------------
[enh] if `display` defined as function call it on init (vitalets)
[enh #218] sourceCache now disables cache totally (vitalets)
[bug #156] conflict of bootstrap datepicker and jQuery UI datepicker (vitalets)
[bug #156] solve conflict of bootstrap datepicker and jQuery UI datepicker (vitalets)
[enh] update bootstrap-datepicker to 1.1.2 (vitalets)
[enh] allow follow links in disabled state (vitalets)
[enh] update combodate to 1.0.4, fix #222 (vitalets)

@ -81,6 +81,12 @@ Makes editable any HTML element on the page. Applied as jQuery method.
this.$element.attr('tabindex', -1); //do not stop focus on element when toggled manually
}
//if display is function it's far more convinient to have autotext = always to render correctly on init
//see https://github.com/vitalets/x-editable-yii/issues/34
if(typeof this.options.display === 'function') {
this.options.autotext = 'always'
}
//check conditions for autotext:
switch(this.options.autotext) {
case 'always':

@ -615,7 +615,7 @@ $(function () {
asyncTest("'display' callback", function () {
var req = 0,
e = $('<a href="#" data-type="select" data-value="2" data-url="post.php"></a>').appendTo(fx).editable({
e = $('<a href="#" data-type="select" data-value="2" data-url="post.php">123</a>').appendTo(fx).editable({
pk: 1,
source: groups,
ajaxOptions: {

@ -374,17 +374,27 @@ $(function () {
asyncTest("'display' callback", function () {
var newText = 'cd<e>;"',
e = $('<a href="#" data-pk="1" data-url="post.php" data-name="text1">abc</a>').appendTo(fx).editable({
counter = 0,
initialVal = 'abc',
e = $('<a href="#" data-pk="1" data-url="post.php" data-name="text1">123</a>').appendTo(fx).editable({
ajaxOptions: {
dataType: 'json'
},
display: function(value, response) {
ok(this === e[0], 'scope is ok');
ok(response.success, 'response param ok');
$(this).text('qq'+value);
}
});
if(counter === 0) {
ok(response === undefined, 'initial autotext ok as display is func');
$(this).text(initialVal);
} else {
ok(this === e[0], 'updating, scope is ok');
ok(response.success, 'response param ok');
$(this).text('qq'+value);
}
counter++;
}
});
equal(e.text(), initialVal, 'initial autotext ok');
e.click()
var p = tip(e);