autosubmit select test + document click tiny refactor
This commit is contained in:
@ -41,55 +41,15 @@ Applied as jQuery method.
|
|||||||
|
|
||||||
//close containers when click outside
|
//close containers when click outside
|
||||||
$(document).on('click.editable', function(e) {
|
$(document).on('click.editable', function(e) {
|
||||||
var element = e.target,
|
var $target = $(e.target);
|
||||||
$target = $(e.target),
|
|
||||||
$clickedContainer = $target.is('.editable-container') ? $target : $target.closest('.editable-container');
|
|
||||||
|
|
||||||
//if click inside some editableContainer --> find corresponding element
|
//if click inside some editableContainer --> no nothing
|
||||||
if($clickedContainer.length) {
|
if($target.is('.editable-container') || $target.parents('.editable-container').length || $target.parents('.ui-datepicker-header').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) {
|
|
||||||
return;
|
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);
|
$(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
|
@type boolean
|
||||||
@default true
|
@default true
|
||||||
**/
|
**/
|
||||||
showbuttons: false
|
showbuttons: true
|
||||||
|
|
||||||
/*todo:
|
/*todo:
|
||||||
Submit strategy. Can be <code>normal|never</code>
|
Submit strategy. Can be <code>normal|never</code>
|
||||||
|
@ -276,7 +276,9 @@
|
|||||||
|
|
||||||
test("should not wrap buttons when parent has position:absolute", function () {
|
test("should not wrap buttons when parent has position:absolute", function () {
|
||||||
var d = $('<div style="position: absolute; top: 200px">').appendTo(fx),
|
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();
|
e.click();
|
||||||
var p = tip(e);
|
var p = tip(e);
|
||||||
@ -348,7 +350,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("showbuttons: false", function () {
|
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
|
showbuttons: false
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -357,7 +359,7 @@
|
|||||||
ok(p.is(':visible'), 'popover visible');
|
ok(p.is(':visible'), 'popover visible');
|
||||||
ok(!p.find('.editable-submit').length, 'submit not rendered');
|
ok(!p.find('.editable-submit').length, 'submit not rendered');
|
||||||
ok(!p.find('.editable-cancel').length, 'cancel 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.
|
//unfortunatly, testing this feature does not always work in browsers. Tested manually.
|
||||||
|
@ -450,5 +450,30 @@ $(function () {
|
|||||||
start();
|
start();
|
||||||
}, timeout);
|
}, 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);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
Reference in New Issue
Block a user