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

@ -80,9 +80,8 @@ Applied as jQuery method.
.editableform(this.formOptions)
.on({
save: $.proxy(this.save, this),
cancel: $.proxy(function(){
this.hide('cancel');
}, this),
cancel: $.proxy(function(){ this.hide('cancel'); }, this),
nochange: $.proxy(function(){ this.hide('nochange'); }, this),
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
rendered: $.proxy(function(){
@ -146,7 +145,7 @@ Applied as jQuery method.
/**
Hides container with form
@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) {
if(!this.tip() || !this.tip().is(':visible') || !this.$element.hasClass('editable-open')) {
@ -159,7 +158,7 @@ Applied as jQuery method.
@event hidden
@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
$('#username').on('hidden', function(e, reason) {
if(reason === 'save' || reason === 'cancel') {

@ -179,11 +179,16 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
return;
}
//if value not changed --> cancel
//if value not changed --> trigger 'nochange' event and return
/*jslint eqeq: true*/
if (!this.options.savenochange && this.input.value2str(newValue) == this.input.value2str(this.value)) {
/*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;
}