added `do not close popup when it is saving value, fix #224
This commit is contained in:
parent
025c4c20cb
commit
9cbcb0e99c
@ -3,6 +3,7 @@ X-editable changelog
|
|||||||
|
|
||||||
Version 1.4.5 wip
|
Version 1.4.5 wip
|
||||||
----------------------------
|
----------------------------
|
||||||
|
[bug #224] do not close popup when it is saving value (vitalets)
|
||||||
[enh] added `submitValue` to `save` event params (vitalets)
|
[enh] added `submitValue` to `save` event params (vitalets)
|
||||||
[enh #259] allow `getValue` method to return value itself, not object (vitalets)
|
[enh #259] allow `getValue` method to return value itself, not object (vitalets)
|
||||||
[enh] add `destroy` method to inputs (vitalets)
|
[enh] add `destroy` method to inputs (vitalets)
|
||||||
|
@ -33,6 +33,9 @@ Applied as jQuery method.
|
|||||||
this.formOptions.scope = this.$element[0];
|
this.formOptions.scope = this.$element[0];
|
||||||
|
|
||||||
this.initContainer();
|
this.initContainer();
|
||||||
|
|
||||||
|
//flag to hide container, when saving value will finish
|
||||||
|
this.delayedHide = false;
|
||||||
|
|
||||||
//bind 'destroyed' listener to destroy container when element is removed from dom
|
//bind 'destroyed' listener to destroy container when element is removed from dom
|
||||||
this.$element.on('destroyed', $.proxy(function(){
|
this.$element.on('destroyed', $.proxy(function(){
|
||||||
@ -137,7 +140,14 @@ Applied as jQuery method.
|
|||||||
save: $.proxy(this.save, this), //click on submit button (value changed)
|
save: $.proxy(this.save, this), //click on submit button (value changed)
|
||||||
nochange: $.proxy(function(){ this.hide('nochange'); }, this), //click on submit button (value NOT changed)
|
nochange: $.proxy(function(){ this.hide('nochange'); }, this), //click on submit button (value NOT changed)
|
||||||
cancel: $.proxy(function(){ this.hide('cancel'); }, this), //click on calcel button
|
cancel: $.proxy(function(){ this.hide('cancel'); }, this), //click on calcel button
|
||||||
show: $.proxy(this.setPosition, this), //re-position container every time form is shown (occurs each time after loading state)
|
show: $.proxy(function() {
|
||||||
|
if(this.delayedHide) {
|
||||||
|
this.hide(this.delayedHide.reason);
|
||||||
|
this.delayedHide = false;
|
||||||
|
} else {
|
||||||
|
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
|
||||||
resize: $.proxy(this.setPosition, this), //this allows to re-position container when form size is changed
|
resize: $.proxy(this.setPosition, this), //this allows to re-position container when form size is changed
|
||||||
rendered: $.proxy(function(){
|
rendered: $.proxy(function(){
|
||||||
@ -218,6 +228,14 @@ Applied as jQuery method.
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if form is saving value, schedule hide
|
||||||
|
if(this.$form.data('editableform').isSaving) {
|
||||||
|
this.delayedHide = {reason: reason};
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
this.delayedHide = false;
|
||||||
|
}
|
||||||
|
|
||||||
this.$element.removeClass('editable-open');
|
this.$element.removeClass('editable-open');
|
||||||
this.innerHide();
|
this.innerHide();
|
||||||
|
|
||||||
@ -293,7 +311,7 @@ Applied as jQuery method.
|
|||||||
**/
|
**/
|
||||||
this.$element.triggerHandler('save', params);
|
this.$element.triggerHandler('save', params);
|
||||||
|
|
||||||
//hide must be after trigger, as saving value may require methods od plugin, applied to input
|
//hide must be after trigger, as saving value may require methods of plugin, applied to input
|
||||||
this.hide('save');
|
this.hide('save');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -60,6 +60,10 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
|
|||||||
//show loading state
|
//show loading state
|
||||||
this.showLoading();
|
this.showLoading();
|
||||||
|
|
||||||
|
//flag showing is form now saving value to server.
|
||||||
|
//It is needed to wait when closing form.
|
||||||
|
this.isSaving = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fired when rendering starts
|
Fired when rendering starts
|
||||||
@event rendering
|
@event rendering
|
||||||
@ -215,9 +219,13 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
|
|||||||
//convert value for submitting to server
|
//convert value for submitting to server
|
||||||
var submitValue = this.input.value2submit(newValue);
|
var submitValue = this.input.value2submit(newValue);
|
||||||
|
|
||||||
|
this.isSaving = true;
|
||||||
|
|
||||||
//sending data to server
|
//sending data to server
|
||||||
$.when(this.save(submitValue))
|
$.when(this.save(submitValue))
|
||||||
.done($.proxy(function(response) {
|
.done($.proxy(function(response) {
|
||||||
|
this.isSaving = false;
|
||||||
|
|
||||||
//run success callback
|
//run success callback
|
||||||
var res = typeof this.options.success === 'function' ? this.options.success.call(this.options.scope, response, newValue) : null;
|
var res = typeof this.options.success === 'function' ? this.options.success.call(this.options.scope, response, newValue) : null;
|
||||||
|
|
||||||
@ -261,6 +269,8 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
|
|||||||
this.$div.triggerHandler('save', {newValue: newValue, submitValue: submitValue, response: response});
|
this.$div.triggerHandler('save', {newValue: newValue, submitValue: submitValue, response: response});
|
||||||
}, this))
|
}, this))
|
||||||
.fail($.proxy(function(xhr) {
|
.fail($.proxy(function(xhr) {
|
||||||
|
this.isSaving = false;
|
||||||
|
|
||||||
var msg;
|
var msg;
|
||||||
if(typeof this.options.error === 'function') {
|
if(typeof this.options.error === 'function') {
|
||||||
msg = this.options.error.call(this.options.scope, xhr, newValue);
|
msg = this.options.error.call(this.options.scope, xhr, newValue);
|
||||||
|
@ -180,6 +180,33 @@ $(function () {
|
|||||||
}, timeout);
|
}, timeout);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
asyncTest("hide when saving value", function () {
|
||||||
|
var newVal = 2,
|
||||||
|
e = $('<a href="#" data-pk="1" data-type="select" data-url="post.php" data-name="text" data-value="1"></a>')
|
||||||
|
.appendTo(fx)
|
||||||
|
.editable({
|
||||||
|
source: groupsArr
|
||||||
|
});
|
||||||
|
|
||||||
|
e.click();
|
||||||
|
var p = tip(e);
|
||||||
|
p.find('select').val(2);
|
||||||
|
p.find('form').submit();
|
||||||
|
|
||||||
|
e.parent().click();
|
||||||
|
|
||||||
|
ok(p.is(':visible'), 'popover still visible');
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
equal(e.data('editable').value, newVal, 'new value saved');
|
||||||
|
ok(!p.is(':visible'), 'popover closed');
|
||||||
|
|
||||||
|
e.remove();
|
||||||
|
start();
|
||||||
|
}, timeout);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
test("show/hide/toggle methods", function () {
|
test("show/hide/toggle methods", function () {
|
||||||
var e = $('<a href="#" data-pk="1" data-url="post.php" data-name="text1">abc</a>').appendTo('#qunit-fixture').editable();
|
var e = $('<a href="#" data-pk="1" data-url="post.php" data-name="text1">abc</a>').appendTo('#qunit-fixture').editable();
|
||||||
e.editable('show');
|
e.editable('show');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user