added submitValue to save event params

This commit is contained in:
vitalets 2013-06-15 20:19:07 +04:00
parent 90868b5bc1
commit 025c4c20cb
3 changed files with 11 additions and 8 deletions
CHANGELOG.txt
src/editable-form
test/unit

@ -3,6 +3,7 @@ X-editable changelog
Version 1.4.5 wip
----------------------------
[enh] added `submitValue` to `save` event params (vitalets)
[enh #259] allow `getValue` method to return value itself, not object (vitalets)
[enh] add `destroy` method to inputs (vitalets)
[enh #164] allow emptytext to be html (vitalets)

@ -212,8 +212,11 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
return;
}
//convert value for submitting to server
var submitValue = this.input.value2submit(newValue);
//sending data to server
$.when(this.save(newValue))
$.when(this.save(submitValue))
.done($.proxy(function(response) {
//run success callback
var res = typeof this.options.success === 'function' ? this.options.success.call(this.options.scope, response, newValue) : null;
@ -246,7 +249,8 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
@event save
@param {Object} event event object
@param {Object} params additional params
@param {mixed} params.newValue submitted value
@param {mixed} params.newValue raw new value
@param {mixed} params.submitValue submitted value as string
@param {Object} params.response ajax response
@example
@ -254,7 +258,7 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
if(params.newValue === 'username') {...}
});
**/
this.$div.triggerHandler('save', {newValue: newValue, response: response});
this.$div.triggerHandler('save', {newValue: newValue, submitValue: submitValue, response: response});
}, this))
.fail($.proxy(function(xhr) {
var msg;
@ -269,10 +273,7 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
}, this));
},
save: function(newValue) {
//convert value for submitting to server
var submitValue = this.input.value2submit(newValue);
save: function(submitValue) {
//try parse composite pk defined as json string in data-pk
this.options.pk = $.fn.editableutils.tryParseJson(this.options.pk, true);

@ -150,12 +150,13 @@ $(function () {
});
asyncTest("event: save / hidden (reason: save)", function () {
expect(2);
expect(3);
var val = '1',
e = $('<a href="#" data-pk="1" data-type="select" data-url="post.php" data-name="text" data-value="'+val+'"></a>').appendTo(fx);
e.on('save', function(event, params) {
equal(params.newValue, 2, 'save triggered, value correct');
equal(params.submitValue, '2', 'submitValue property correct');
});
e.on('hidden', function(event, reason) {