autosubmit select test + document click tiny refactor
This commit is contained in:
parent
ed836c2271
commit
a62afc9180
@ -41,55 +41,15 @@ Applied as jQuery method.
|
||||
|
||||
//close containers when click outside
|
||||
$(document).on('click.editable', function(e) {
|
||||
var element = e.target,
|
||||
$target = $(e.target),
|
||||
$clickedContainer = $target.is('.editable-container') ? $target : $target.closest('.editable-container');
|
||||
var $target = $(e.target);
|
||||
|
||||
//if click inside some editableContainer --> find corresponding element
|
||||
if($clickedContainer.length) {
|
||||
$('.editable-open').each(function(i, el){
|
||||
if($(el).data('editableContainer').tip()[0] === $clickedContainer[0]) {
|
||||
element = el;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//close all open containers (except one)
|
||||
EditableContainer.prototype.closeOthers(element);
|
||||
|
||||
/* $('.editable-open').each(function(){
|
||||
//if click target is editable element --> do nothing with el
|
||||
if(this === e.target) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $el = $(this),
|
||||
ec = $el.data('editableContainer');
|
||||
|
||||
//if click in some editableContainer and current el is it's owner --> do nothing with el
|
||||
if($clickedContainer.length && ec.tip()[0] === $clickedContainer[0]) {
|
||||
return;
|
||||
}
|
||||
|
||||
//otherwise cancel or submit el's container
|
||||
if(ec.options.onblur === 'cancel') {
|
||||
$el.data('editableContainer').hide();
|
||||
} else if(ec.options.onblur === 'submit') {
|
||||
$el.data('editableContainer').tip().find('form').submit();
|
||||
}
|
||||
}); */
|
||||
|
||||
//if click inside container --> do nothing
|
||||
// if($target.is('.editable-container') || $target.parents('.editable-container').length || $target.parents('.ui-datepicker-header').length) {
|
||||
/*
|
||||
if($target.is('.editable-container') || $target.parents('.editable-container').length || $target.parents('.ui-datepicker-header').length) {
|
||||
//if click inside some editableContainer --> no nothing
|
||||
if($target.is('.editable-container') || $target.parents('.editable-container').length || $target.parents('.ui-datepicker-header').length) {
|
||||
return;
|
||||
} else {
|
||||
//close all open containers (except one)
|
||||
EditableContainer.prototype.closeOthers(e.target);
|
||||
}
|
||||
|
||||
//close all other containers
|
||||
$('.editable-container').find('.editable-cancel').click();
|
||||
*/
|
||||
});
|
||||
|
||||
$(document).data('editable-handlers-attached', true);
|
||||
|
@ -450,7 +450,7 @@ Editableform is linked with one of input types, e.g. 'text' or 'select'.
|
||||
@type boolean
|
||||
@default true
|
||||
**/
|
||||
showbuttons: false
|
||||
showbuttons: true
|
||||
|
||||
/*todo:
|
||||
Submit strategy. Can be <code>normal|never</code>
|
||||
|
@ -276,7 +276,9 @@
|
||||
|
||||
test("should not wrap buttons when parent has position:absolute", function () {
|
||||
var d = $('<div style="position: absolute; top: 200px">').appendTo(fx),
|
||||
e = $('<a href="#" data-pk="1" data-url="post.php" data-name="text1">abc</a>').appendTo(d).editable();
|
||||
e = $('<a href="#" data-pk="1" data-url="post.php" data-name="text1">abc</a>').appendTo(d).editable({
|
||||
showbuttons: true
|
||||
});
|
||||
|
||||
e.click();
|
||||
var p = tip(e);
|
||||
@ -348,7 +350,7 @@
|
||||
});
|
||||
|
||||
test("showbuttons: false", function () {
|
||||
var e = $('<a href="#" id="a"></a>').appendTo('#qunit-fixture').editable({
|
||||
var e = $('<a href="#" id="a" data-type="text"></a>').appendTo('#qunit-fixture').editable({
|
||||
showbuttons: false
|
||||
});
|
||||
|
||||
@ -357,7 +359,7 @@
|
||||
ok(p.is(':visible'), 'popover visible');
|
||||
ok(!p.find('.editable-submit').length, 'submit not rendered');
|
||||
ok(!p.find('.editable-cancel').length, 'cancel not rendered');
|
||||
ok(!p.find('.editable-buttons').length, '.editable-buttons block not rendered');
|
||||
ok(!p.find('.editable-buttons').length, '.editable-buttons block not rendered');
|
||||
});
|
||||
|
||||
//unfortunatly, testing this feature does not always work in browsers. Tested manually.
|
||||
|
@ -450,5 +450,30 @@ $(function () {
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
|
||||
asyncTest("autosubmit when showbuttons=false", function () {
|
||||
expect(4);
|
||||
var e = $('<a href="#" data-type="select" data-value="2" data-url="post.php">customer</a>').appendTo(fx).editable({
|
||||
pk: 1,
|
||||
source: groups,
|
||||
showbuttons: false
|
||||
}),
|
||||
selected = 3;
|
||||
|
||||
e.click();
|
||||
var p = tip(e);
|
||||
equal(p.find('select').val(), e.data('editable').value, 'selected value correct');
|
||||
|
||||
p.find('select').val(selected);
|
||||
p.find('select').trigger('change');
|
||||
|
||||
setTimeout(function() {
|
||||
ok(!p.is(':visible'), 'popover closed');
|
||||
equal(e.data('editable').value, selected, 'new value saved')
|
||||
equal(e.text(), groups[selected], 'text shown correctly')
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user