diff --git a/CHANGELOG.txt b/CHANGELOG.txt index cfce619..27330f6 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -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) diff --git a/src/element/editable-element.js b/src/element/editable-element.js index 9c9f181..077cef1 100644 --- a/src/element/editable-element.js +++ b/src/element/editable-element.js @@ -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': diff --git a/test/unit/select.js b/test/unit/select.js index 1a8f9ae..f6c7561 100644 --- a/test/unit/select.js +++ b/test/unit/select.js @@ -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: { diff --git a/test/unit/text.js b/test/unit/text.js index 66da9a0..490faaf 100644 --- a/test/unit/text.js +++ b/test/unit/text.js @@ -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);