display option ready
This commit is contained in:
@ -4,21 +4,28 @@ $(function () {
|
||||
setup: function(){
|
||||
sfx = $('#qunit-fixture'),
|
||||
fx = $('#async-fixture');
|
||||
$.support.transition = false;
|
||||
}
|
||||
});
|
||||
|
||||
asyncTest("should load options, set correct value and save new value", function () {
|
||||
var sep = '-',
|
||||
var sep = '<br>',
|
||||
newValue,
|
||||
e = $('<a href="#" data-type="checklist" data-url="post.php"></a>').appendTo(fx).editable({
|
||||
e = $('<a href="#" data-type="checklist" data-url="post-checklist.php"></a>').appendTo(fx).editable({
|
||||
pk: 1,
|
||||
source: groupsArr,
|
||||
value: [2, 3],
|
||||
viewseparator: sep
|
||||
value: [2, 3]
|
||||
});
|
||||
|
||||
equal(e.text(), groups[2]+sep+groups[3], 'autotext ok');
|
||||
equal(e.html(), groups[2]+sep+groups[3], 'autotext ok');
|
||||
|
||||
$.mockjax({
|
||||
url: 'post-checklist.php',
|
||||
response: function(settings) {
|
||||
ok($.isArray(settings.data.value), 'value submitted as array');
|
||||
equal(settings.data.value.sort().join(''), [newValue, 3].join(''), 'submitted array correct');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
e.click();
|
||||
var p = tip(e);
|
||||
@ -28,8 +35,8 @@ $(function () {
|
||||
equal(p.find('input[type="checkbox"]:checked').eq(1).val(), 3, '2nd checked');
|
||||
|
||||
//set new value
|
||||
p.find('input[type="checkbox"]:checked').eq(0).click();
|
||||
p.find('input[type="checkbox"]').first().click();
|
||||
p.find('input[type="checkbox"]:checked').eq(0).click(); //uncheck 2
|
||||
p.find('input[type="checkbox"]').first().click(); //check first
|
||||
newValue = p.find('input[type="checkbox"]').first().val();
|
||||
|
||||
//submit
|
||||
@ -39,7 +46,7 @@ $(function () {
|
||||
ok(!p.is(':visible'), 'popup closed');
|
||||
|
||||
equal(e.data('editable').value.join(''), [newValue, 3].join(''), 'new value ok')
|
||||
equal(e.text(), groups[newValue]+sep+groups[3], 'new text ok');
|
||||
equal(e.html(), groups[newValue]+'<br>'+groups[3], 'new text ok');
|
||||
|
||||
// open container again to see what checked
|
||||
e.click()
|
||||
@ -54,40 +61,5 @@ $(function () {
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
|
||||
asyncTest("limit option", function () {
|
||||
var e = $('<a href="#" data-type="checklist" data-value="2,3" data-url="post.php"></a>').appendTo(fx).editable({
|
||||
pk: 1,
|
||||
source: groupsArr,
|
||||
limit: 1,
|
||||
limitText: '{checked} of {count}'
|
||||
});
|
||||
|
||||
equal(e.text(), '2 of '+groupsArr.length, 'autotext ok');
|
||||
|
||||
e.click();
|
||||
var p = tip(e);
|
||||
|
||||
equal(p.find('input[type="checkbox"]:checked').length, 2, 'checked count ok');
|
||||
equal(p.find('input[type="checkbox"]:checked').eq(0).val(), 2, '1st checked');
|
||||
equal(p.find('input[type="checkbox"]:checked').eq(1).val(), 3, '2nd checked');
|
||||
|
||||
//set new value
|
||||
p.find('input[type="checkbox"]').first().click();
|
||||
newValue = p.find('input[type="checkbox"]').first().val();
|
||||
|
||||
//submit
|
||||
p.find('form').submit();
|
||||
|
||||
setTimeout(function() {
|
||||
ok(!p.is(':visible'), 'popup closed');
|
||||
|
||||
equal(e.text(), '3 of '+groupsArr.length, 'autotext ok');
|
||||
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
|
||||
|
||||
});
|
@ -523,6 +523,34 @@ $(function () {
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
});
|
||||
|
||||
asyncTest("'display' callback", function () {
|
||||
var e = $('<a href="#" data-type="select" data-value="2" data-url="post.php"></a>').appendTo(fx).editable({
|
||||
pk: 1,
|
||||
source: groups,
|
||||
display: function(value, sourceData) {
|
||||
var els = $.grep(sourceData, function(o) {return o.value == value;});
|
||||
$(this).text('qq' + els[0].text);
|
||||
}
|
||||
}),
|
||||
selected = 3;
|
||||
|
||||
equal(e.text(), 'qq'+groups[2], 'autotext display ok');
|
||||
|
||||
e.click();
|
||||
var p = tip(e);
|
||||
|
||||
p.find('select').val(selected);
|
||||
p.find('form').submit();
|
||||
|
||||
setTimeout(function() {
|
||||
ok(!p.is(':visible'), 'popover closed');
|
||||
equal(e.data('editable').value, selected, 'new value saved')
|
||||
equal(e.text(), 'qq'+groups[selected], 'text shown correctly')
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
|
||||
});
|
@ -454,6 +454,31 @@ $(function () {
|
||||
delete $.fn.editable.defaults.name;
|
||||
var e = $('<a href="#" id="cde">abc</a>').appendTo('#qunit-fixture').editable();
|
||||
equal(e.data('editable').options.name, 'cde', 'name is taken from id');
|
||||
});
|
||||
});
|
||||
|
||||
asyncTest("'display' callback", function () {
|
||||
var newText = 'cd<e>;"',
|
||||
e = $('<a href="#" data-pk="1" data-url="post.php" data-name="text1">abc</a>').appendTo(fx).editable({
|
||||
display: function(value) {
|
||||
ok(this === e[0], 'scope is ok');
|
||||
$(this).text('qq'+value);
|
||||
}
|
||||
});
|
||||
|
||||
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() {
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
equal(e.text(), 'qq'+newText, 'custom display ok');
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
|
||||
});
|
||||
|
||||
});
|
@ -34,8 +34,8 @@ $(function () {
|
||||
var e = $('<a href="#" data-pk="1" data-url="post.php">'+v1+'</a>').appendTo(fx).editable({
|
||||
type: 'textarea',
|
||||
send: 'ifpk',
|
||||
success: function(data) {
|
||||
return false;
|
||||
success: function(response, newvalue) {
|
||||
equal(newvalue, v2, 'value in success ok');
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user