params as function overwrite original data instead of append
This commit is contained in:
parent
5b18620b99
commit
c674cdcfcb
@ -4,6 +4,7 @@ X-editable changelog
|
||||
|
||||
Version 1.2.1 wip
|
||||
----------------------------
|
||||
[enh #40] 'params' option defined as function overwrites original ajax data instead of appending (vitalets)
|
||||
[bug] datepicker: error when click on arrows after clear date (vitalets)
|
||||
[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)
|
||||
|
@ -264,7 +264,7 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
|
||||
|
||||
//additional params
|
||||
if(typeof this.options.params === 'function') {
|
||||
$.extend(params, this.options.params.call(this.options.scope, params));
|
||||
params = this.options.params.call(this.options.scope, params);
|
||||
} else {
|
||||
//try parse json in single quotes (from data-params attribute)
|
||||
this.options.params = $.fn.editableutils.tryParseJson(this.options.params, true);
|
||||
@ -375,10 +375,13 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
|
||||
**/
|
||||
url:null,
|
||||
/**
|
||||
Additional params for submit. Function can be used to calculate params dynamically
|
||||
Additional params for submit. If defined as <code>object</code> - it is **appended** to original ajax data (pk, name and value).
|
||||
If defined as <code>function</code> - returned object **overwrites** original ajax data.
|
||||
@example
|
||||
params: function(params) {
|
||||
return { a: 1 };
|
||||
//originally params contain pk, name and value
|
||||
params.a = 1;
|
||||
return params;
|
||||
}
|
||||
|
||||
@property params
|
||||
|
@ -444,6 +444,81 @@
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
asyncTest("should submit all required params", function () {
|
||||
var e = $('<a href="#" data-pk="1" data-url="post-resp.php">abc</a>').appendTo(fx).editable({
|
||||
name: 'username',
|
||||
params: {
|
||||
q: 2
|
||||
},
|
||||
ajaxOptions: {
|
||||
dataType: 'json'
|
||||
},
|
||||
success: function(resp) {
|
||||
equal(resp.dataType, 'json', 'dataType ok');
|
||||
equal(resp.data.pk, 1, 'pk ok');
|
||||
equal(resp.data.name, 'username', 'name ok');
|
||||
equal(resp.data.value, newText, 'value ok');
|
||||
equal(resp.data.q, 2, 'additional params ok');
|
||||
}
|
||||
}),
|
||||
newText = 'cd<e>;"'
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
|
||||
ok(p.find('input[type=text]').length, 'input exists')
|
||||
p.find('input').val(newText);
|
||||
p.find('form').submit();
|
||||
|
||||
setTimeout(function() {
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
|
||||
});
|
||||
|
||||
asyncTest("params as function", function () {
|
||||
var e = $('<a href="#" data-pk="1" data-url="post-params-func.php">abc</a>').appendTo(fx).editable({
|
||||
name: 'username',
|
||||
params: function(params) {
|
||||
ok(this === e[0], 'scope is ok');
|
||||
equal(params.pk, 1, 'params in func already have values (pk)');
|
||||
return $.extend(params, {q: 2, pk: 3});
|
||||
},
|
||||
ajaxOptions: {
|
||||
headers: {"myHeader": "123"}
|
||||
}
|
||||
}),
|
||||
newText = 'cd<e>;"'
|
||||
|
||||
$.mockjax({
|
||||
url: 'post-params-func.php',
|
||||
response: function(settings) {
|
||||
equal(settings.dataType, undefined, 'dataType undefined (correct)');
|
||||
equal(settings.data.pk, 3, 'pk ok');
|
||||
equal(settings.data.name, 'username', 'name ok');
|
||||
equal(settings.data.value, newText, 'value ok');
|
||||
equal(settings.data.q, 2, 'additional params ok');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
|
||||
ok(p.find('input[type=text]').length, 'input exists')
|
||||
p.find('input').val(newText);
|
||||
p.find('form').submit();
|
||||
|
||||
setTimeout(function() {
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
|
||||
});
|
||||
|
||||
|
||||
}(jQuery));
|
@ -211,79 +211,6 @@ $(function () {
|
||||
|
||||
});
|
||||
|
||||
|
||||
asyncTest("should submit all required params", function () {
|
||||
var e = $('<a href="#" data-pk="1" data-url="post-resp.php">abc</a>').appendTo(fx).editable({
|
||||
name: 'username',
|
||||
params: {
|
||||
q: 2
|
||||
},
|
||||
ajaxOptions: {
|
||||
dataType: 'json'
|
||||
},
|
||||
success: function(resp) {
|
||||
equal(resp.dataType, 'json', 'dataType ok');
|
||||
equal(resp.data.pk, 1, 'pk ok');
|
||||
equal(resp.data.name, 'username', 'name ok');
|
||||
equal(resp.data.value, newText, 'value ok');
|
||||
equal(resp.data.q, 2, 'additional params ok');
|
||||
}
|
||||
}),
|
||||
newText = 'cd<e>;"'
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
|
||||
ok(p.find('input[type=text]').length, 'input exists')
|
||||
p.find('input').val(newText);
|
||||
p.find('form').submit();
|
||||
|
||||
setTimeout(function() {
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
|
||||
});
|
||||
|
||||
asyncTest("params as function", function () {
|
||||
var e = $('<a href="#" data-pk="1" data-url="post-params-func.php">abc</a>').appendTo(fx).editable({
|
||||
name: 'username',
|
||||
params: function(params) {
|
||||
ok(this === e[0], 'scope is ok');
|
||||
equal(params.pk, 1, 'params in func already have values (pk)');
|
||||
return { q: 2, pk: 3 };
|
||||
},
|
||||
ajaxOptions: {
|
||||
headers: {"myHeader": "123"}
|
||||
}
|
||||
}),
|
||||
newText = 'cd<e>;"'
|
||||
|
||||
$.mockjax({
|
||||
url: 'post-params-func.php',
|
||||
response: function(settings) {
|
||||
equal(settings.dataType, undefined, 'dataType undefined (correct)');
|
||||
equal(settings.data.pk, 3, 'pk ok');
|
||||
equal(settings.data.name, 'username', 'name ok');
|
||||
equal(settings.data.value, newText, 'value ok');
|
||||
equal(settings.data.q, 2, 'additional params ok');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
|
||||
ok(p.find('input[type=text]').length, 'input exists')
|
||||
p.find('input').val(newText);
|
||||
p.find('form').submit();
|
||||
|
||||
setTimeout(function() {
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
|
||||
});
|
||||
|
||||
asyncTest("ajaxOptions", function () {
|
||||
var e = $('<a href="#" data-pk="1" data-url="post-options.php">abc</a>').appendTo(fx).editable({
|
||||
|
Loading…
x
Reference in New Issue
Block a user