composite pk defined in data-pk attr

This commit is contained in:
vitalets 2012-12-04 18:21:18 +04:00
parent 4f5b5062b6
commit 6ff1364a86
3 changed files with 35 additions and 1 deletions
CHANGELOG.txt
src/editable-form
test/unit

@ -4,7 +4,9 @@ X-editable changelog
Version 1.1.2 wip
----------------------------
[bug #34] inputclass span* broken with fluid layout. Changed to input-*. (vitalets)
[enh] composite pk can be defined as JSON in data-pk attribute (vitalets)
[enh #30] new option 'sourceCache' true|false to disable cache for select (vitalets)
[bug #34] inputclass span* broken with fluid bootstrap layout. Classes changed to 'input-*'. (vitalets)
[enh] utils now added to $.fn.editableutils instead of $.fn.editableform.utils (vitalets)
[enh] input types now added to $.fn.editabletypes instead of $.fn.editableform.types (vitalets)
[enh] playground and tests now use requirejs (vitalets)

@ -227,6 +227,9 @@ Editableform is linked with one of input types, e.g. 'text' or 'select'.
},
save: function(value) {
//try parse composite pk defined as json string in data-pk
this.options.pk = $.fn.editableutils.tryParseJson(this.options.pk, true);
var pk = (typeof this.options.pk === 'function') ? this.options.pk.call(this) : this.options.pk,
send = !!(typeof this.options.url === 'function' || (this.options.url && ((this.options.send === 'always') || (this.options.send === 'auto' && pk)))),
params, ajaxOptions;

@ -362,6 +362,35 @@
ok(!p.find('.editable-buttons').length, '.editable-buttons block not rendered');
});
asyncTest("composite pk defined as json in data-pk attribute", function () {
var e = $('<a href="#" data-pk="{a: 1, b: 2}" data-url="post-pk.php">abc</a>').appendTo(fx).editable({
name: 'username'
}),
newText = 'cd<e>;"'
$.mockjax({
url: 'post-pk.php',
response: function(settings) {
equal(settings.data.pk.a, 1, 'first part ok');
equal(settings.data.pk.b, 2, 'second part 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);
});
//unfortunatly, testing this feature does not always work in browsers. Tested manually.
/*
test("enablefocus option", function () {