diff --git a/CHANGELOG.txt b/CHANGELOG.txt index bc028fb..ab97eb4 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,8 @@ X-editable changelog Version 1.1.2 wip ---------------------------- +[enh] all callbacks scope changed to element (vitalets) +[enh] new option 'cancelnochange' to cancel or submit value when it was not changed in form (vitalets) [enh] composite pk can be defined as JSON in data-pk attribute (vitalets) [enh #30] new option 'sourceCache' true|false to disable cache for select (vitalets) [bug #34] inputclass span* broken with fluid bootstrap layout. Classes changed to 'input-*'. (vitalets) diff --git a/src/element/editable-element.js b/src/element/editable-element.js index 9203df4..a148c3a 100644 --- a/src/element/editable-element.js +++ b/src/element/editable-element.js @@ -222,12 +222,15 @@ Makes editable any HTML element on the page. Applied as jQuery method. if(!this.container) { var containerOptions = $.extend({}, this.options, { value: this.value, - autohide: false //element will take care to show/hide container + autohide: false, //element will take care to show/hide container. Otherwise hide() will be called twice + scope: this.$element[0] //set scope to element }); this.$element.editableContainer(containerOptions); this.$element.on({ save: $.proxy(this.save, this), - cancel: $.proxy(this.hide, this) + cancel: $.proxy(function(){ + this.hide(); + }, this) }); this.container = this.$element.data('editableContainer'); } else if(this.container.tip().is(':visible')) { @@ -338,7 +341,7 @@ Makes editable any HTML element on the page. Applied as jQuery method. if(this.container) { this.container.activate(); } - } + } }; /* EDITABLE PLUGIN DEFINITION @@ -526,7 +529,7 @@ Makes editable any HTML element on the page. Applied as jQuery method. **/ autotext: 'auto', /** - Wether to return focus on element after form is closed. + Whether to return focus on element after form is closed. This allows fully keyboard input. @property enablefocus diff --git a/test/unit/text.js b/test/unit/text.js index 8457c50..e9ad7d0 100644 --- a/test/unit/text.js +++ b/test/unit/text.js @@ -43,16 +43,16 @@ $(function () { asyncTest("should load correct value and save new entered text (and value)", function () { var v = 'ab<b>"', esc_v = $('<div>').text(v).html(), - e = $('<a href="#" data-pk="1" data-name="text1" data-url="post-text.php" data-params="{\'q\': \'w\'}">'+esc_v+'</a>').appendTo(fx).editable({ - success: function(data) { - return false; + e = $('<a href="#" data-pk="1" data-name="text1" data-url="post-text-main.php" data-params="{\'q\': \'w\'}">'+esc_v+'</a>').appendTo(fx).editable({ + success: function(response, newValue) { + equal(newValue, newText, 'new value in success correct'); } }), data, - newText = 'cd<e>;"'; + newText = 'cd>e>;"'; $.mockjax({ - url: 'post-text.php', + url: 'post-text-main.php', response: function(settings) { data = settings.data; } @@ -61,13 +61,13 @@ $(function () { e.click() var p = tip(e); - ok(p.is(':visible'), 'popover visible') - ok(p.find('.editableform-loading').length, 'loading class exists') - ok(!p.find('.editableform-loading').is(':visible'), 'loading class is hidden') - ok(p.find('input[type=text]').length, 'input exists') - equal(p.find('input[type=text]').val(), v, 'input contain correct value') + ok(p.is(':visible'), 'popover visible'); + ok(p.find('.editableform-loading').length, 'loading class exists'); + ok(!p.find('.editableform-loading').is(':visible'), 'loading class is hidden'); + ok(p.find('input[type=text]').length, 'input exists'); + equal(p.find('input[type=text]').val(), v, 'input contain correct value'); p.find('input').val(newText); - p.find('button[type=submit]').click(); + p.find('form').submit(); ok(p.find('.editableform-loading').is(':visible'), 'loading class is visible'); setTimeout(function() { @@ -88,7 +88,10 @@ $(function () { asyncTest("should show error on server validation", function () { var msg = 'required', e = $('<a href="#" data-name="text1">abc</a>').appendTo(fx).editable({ - validate: function(value) { if(value == '') return msg; } + validate: function(value) { + ok(this === e[0], 'scope is ok'); + if(value == '') return msg; + } }), newText = ''; @@ -153,6 +156,7 @@ $(function () { var newText = 'cd<e>;"', e = $('<a href="#" data-pk="1" data-url="post.php" data-name="text1">abc</a>').appendTo(fx).editable({ success: function(response, newValue) { + ok(this === e[0], 'scope is ok'); equal(newValue, newText, 'value in success passed correctly'); return 'error'; } @@ -242,6 +246,7 @@ $(function () { var e = $('<a href="#" data-pk="1" data-url="post-resp.php">abc</a>').appendTo(fx).editable({ name: 'username', params: function(params) { + ok(this === e[0], 'scope is ok'); equal(params.pk, 1, 'params in func already have values (pk)'); return { q: 2, pk: 3 }; }, @@ -304,11 +309,12 @@ $(function () { asyncTest("submit to url defined as function", function () { - expect(3); + expect(4); var newText = 'qwe', //should be called even without pk! e = $('<a href="#" data-pk1="1" id="a"></a>').appendTo(fx).editable({ url: function(params) { + ok(this === e[0], 'scope is ok'); ok(params.value, newText, 'new text passed in users function'); var d = new $.Deferred; return d.reject('my error');