nochange reason for hidden event

This commit is contained in:
vitalets
2012-12-08 16:25:30 +04:00
parent c764f7ba39
commit 48eff4a33d
4 changed files with 22 additions and 10 deletions

@ -4,8 +4,9 @@ X-editable changelog
Version 1.2.1 wip Version 1.2.1 wip
---------------------------- ----------------------------
[enh] 'hidden' event: added possible value of reason param - 'nochange'. Occurs when form is submitted but value was not changed (vitalets)
[enh] 'submit' method changed: error-callback's parameter simplified (vitalets) [enh] 'submit' method changed: error-callback's parameter simplified (vitalets)
[enh] 'submit' method changed: now when response 200 OK it does not set pk automatically, use success callback (vitalets) [enh] 'submit' method changed: now when response 200 OK it does not set pk automatically (vitalets)
[enh] 'submit' method changed: removed dataType='json'. Use 'ajaxOptions' to specify dataType if needed (vitalets) [enh] 'submit' method changed: removed dataType='json'. Use 'ajaxOptions' to specify dataType if needed (vitalets)
[enh] removed default ajax dataType='json'. Use 'ajaxOptions' to specify dataType if needed (vitalets) [enh] removed default ajax dataType='json'. Use 'ajaxOptions' to specify dataType if needed (vitalets)
[enh] select: do not show 'sourceError' in element during autotext execution (vitalets) [enh] select: do not show 'sourceError' in element during autotext execution (vitalets)

@ -80,9 +80,8 @@ Applied as jQuery method.
.editableform(this.formOptions) .editableform(this.formOptions)
.on({ .on({
save: $.proxy(this.save, this), save: $.proxy(this.save, this),
cancel: $.proxy(function(){ cancel: $.proxy(function(){ this.hide('cancel'); }, this),
this.hide('cancel'); nochange: $.proxy(function(){ this.hide('nochange'); }, this),
}, this),
show: $.proxy(this.setPosition, this), //re-position container every time form is shown (occurs each time after loading state) show: $.proxy(this.setPosition, this), //re-position container every time form is shown (occurs each time after loading state)
rendering: $.proxy(this.setPosition, this), //this allows to place container correctly when loading shown rendering: $.proxy(this.setPosition, this), //this allows to place container correctly when loading shown
rendered: $.proxy(function(){ rendered: $.proxy(function(){
@ -146,7 +145,7 @@ Applied as jQuery method.
/** /**
Hides container with form Hides container with form
@method hide() @method hide()
@param {string} reason Reason caused hiding. Can be <code>save|cancel|onblur|undefined (=manual)</code> @param {string} reason Reason caused hiding. Can be <code>save|cancel|onblur|nochange|undefined (=manual)</code>
**/ **/
hide: function(reason) { hide: function(reason) {
if(!this.tip() || !this.tip().is(':visible') || !this.$element.hasClass('editable-open')) { if(!this.tip() || !this.tip().is(':visible') || !this.$element.hasClass('editable-open')) {
@ -159,7 +158,7 @@ Applied as jQuery method.
@event hidden @event hidden
@param {object} event event object @param {object} event event object
@param {string} reason Reason caused hiding. Can be <code>save|cancel|onblur|undefined (=manual)</code> @param {string} reason Reason caused hiding. Can be <code>save|cancel|onblur|nochange|undefined (=manual)</code>
@example @example
$('#username').on('hidden', function(e, reason) { $('#username').on('hidden', function(e, reason) {
if(reason === 'save' || reason === 'cancel') { if(reason === 'save' || reason === 'cancel') {

@ -179,11 +179,16 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
return; return;
} }
//if value not changed --> cancel //if value not changed --> trigger 'nochange' event and return
/*jslint eqeq: true*/ /*jslint eqeq: true*/
if (!this.options.savenochange && this.input.value2str(newValue) == this.input.value2str(this.value)) { if (!this.options.savenochange && this.input.value2str(newValue) == this.input.value2str(this.value)) {
/*jslint eqeq: false*/ /*jslint eqeq: false*/
this.cancel(); /**
Fired when value not changed but form is submitted. Requires savenochange = false.
@event nochange
@param {Object} event event object
**/
this.$div.triggerHandler('nochange');
return; return;
} }

@ -79,8 +79,8 @@ $(function () {
e.editable(); e.editable();
}); });
asyncTest("events: shown / hidden (reason: cancel, onblur, manual)", function () { asyncTest("events: shown / hidden (reason: cancel, onblur, nochange, manual)", function () {
expect(11); expect(15);
var val = '1', test_reason, var val = '1', test_reason,
e = $('<a href="#" data-pk="1" data-type="select" data-url="post.php" data-name="text" data-value="'+val+'"></a>').appendTo(fx); e = $('<a href="#" data-pk="1" data-type="select" data-url="post.php" data-name="text" data-value="'+val+'"></a>').appendTo(fx);
@ -113,6 +113,13 @@ $(function () {
e.parent().click(); e.parent().click();
ok(!p.is(':visible'), 'popover closed'); ok(!p.is(':visible'), 'popover closed');
test_reason = 'nochange'
e.click();
p = tip(e);
ok(p.is(':visible'), 'popover shown');
p.find('form').submit(); //submit value without changes
ok(!p.is(':visible'), 'popover closed');
test_reason = 'manual' test_reason = 'manual'
e.click(); e.click();
p = tip(e); p = tip(e);