diff --git a/src/editable-form/editable-form.js b/src/editable-form/editable-form.js index 19c0884..ccaf057 100644 --- a/src/editable-form/editable-form.js +++ b/src/editable-form/editable-form.js @@ -181,7 +181,7 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc. //if value not changed --> cancel /*jslint eqeq: true*/ - if (newValueStr == this.input.value2str(this.value)) { + if (this.options.cancelnochange && newValueStr == this.input.value2str(this.value)) { /*jslint eqeq: false*/ this.cancel(); return; @@ -472,7 +472,16 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc. @default null @since 1.1.2 **/ - scope: null + scope: null, + /** + Whether to cancel or submit value when it was not changed. + + @property cancelnochange + @type boolean + @default true + @since 1.1.2 + **/ + cancelnochange: true }; /* diff --git a/test/unit/common.js b/test/unit/common.js index cc614f6..1a75f1c 100644 --- a/test/unit/common.js +++ b/test/unit/common.js @@ -389,6 +389,64 @@ }, timeout); }); + + asyncTest("cancelnochange: true", function () { + var v = 'abc', + e = $('<a href="#" data-type="text" data-pk="1" data-url="post-no.php" data-name="text1">'+v+'</a>').appendTo(fx).editable({ + cancelnochange: true + }), + req = 0; + + $.mockjax({ + url: 'post-no.php', + response: function() { + req++; + } + }); + + e.click(); + var p = tip(e); + ok(p.is(':visible'), 'popover visible'); + p.find('input[type="text"]').val(v); + p.find('form').submit(); + + setTimeout(function() { + ok(!p.is(':visible'), 'popover closed'); + equal(req, 0, 'request was not performed'); + e.remove(); + start(); + }, timeout); + }); + + asyncTest("cancelnochange: false", function () { + var v = 'abc', + e = $('<a href="#" data-type="text" data-pk="1" data-url="post-yes.php" data-name="text1">'+v+'</a>').appendTo(fx).editable({ + cancelnochange: false + }), + req = 0; + + $.mockjax({ + url: 'post-yes.php', + response: function() { + req++; + } + }); + + e.click(); + var p = tip(e); + ok(p.is(':visible'), 'popover visible'); + p.find('input[type="text"]').val(v); + p.find('form').submit(); + + setTimeout(function() { + ok(!p.is(':visible'), 'popover closed'); + equal(req, 1, 'request was performed'); + e.remove(); + start(); + }, timeout); + }); + + //unfortunatly, testing this feature does not always work in browsers. Tested manually. diff --git a/test/unit/text.js b/test/unit/text.js index f7fc3e9..8457c50 100644 --- a/test/unit/text.js +++ b/test/unit/text.js @@ -149,30 +149,6 @@ $(function () { }); */ - asyncTest("should not perform request if value not changed", function () { - var e = $('<a href="#" data-pk="1" data-url="post-no.php" data-name="text1">abc</a>').appendTo(fx).editable(), - req = 0; - - $.mockjax({ - url: 'post-no.php', - response: function() { - req++; - } - }); - - e.click(); - var p = tip(e); - ok(p.is(':visible'), 'popover visible'); - p.find('button[type=submit]').click(); - - setTimeout(function() { - ok(!p.is(':visible'), 'popover closed'); - equal(req, 0, 'request was not performed'); - e.remove(); - start(); - }, timeout); - }); - asyncTest("should show error if success callback returns string", function () { var newText = 'cd<e>;"', e = $('<a href="#" data-pk="1" data-url="post.php" data-name="text1">abc</a>').appendTo(fx).editable({