dateui: clear button does not submit, fixes

This commit is contained in:
vitalets 2013-10-05 14:29:58 +04:00
parent 0b929fe204
commit 0ef1ad5ba4
3 changed files with 62 additions and 7 deletions
CHANGELOG.txt
src/inputs/dateui
test/unit

@ -1,6 +1,12 @@
X-editable changelog
=============================
Version 1.5.1 wip
----------------------------
[bug #374] dateui: clear button does not submit (vitalets)
Version 1.5.0 Oct 1, 2013
----------------------------
[enh #362] add twitter typeahead.js (vitalets)

@ -119,15 +119,22 @@ $(function(){
clear: function() {
this.$input.datepicker('setDate', null);
// submit automatically whe that are no buttons
if(this.isAutosubmit) {
this.submit();
}
},
autosubmit: function() {
this.$input.on('mouseup', 'table.ui-datepicker-calendar a.ui-state-default', function(e){
var $form = $(this).closest('form');
setTimeout(function() {
$form.submit();
}, 200);
});
this.isAutosubmit = true;
this.$input.on('mouseup', 'table.ui-datepicker-calendar a.ui-state-default', $.proxy(this.submit, this));
},
submit: function() {
var $form = this.$input.closest('form');
setTimeout(function() {
$form.submit();
}, 200);
}
});

@ -142,6 +142,48 @@ $(function () {
start();
}, 500);
});
});
asyncTest("clear button in no-buttons mode", function () {
var d = '15.05.1984',
f = 'dd.mm.yyyy',
e = $('<a href="#" data-type="date" data-pk="1" data-url="post-date-clear-no-buttons">'+d+'</a>').appendTo(fx).editable({
format: f,
showbuttons: false
});
$.mockjax({
url: 'post-date-clear-no-buttons',
response: function(settings) {
equal(settings.data.value, '', 'submitted value correct');
}
});
equal(frmt(e.data('editable').value, 'dd.mm.yyyy'), d, 'value correct');
e.click();
var p = tip(e);
ok(p.find('.ui-datepicker').is(':visible'), 'datepicker exists');
equal(frmt(e.data('editable').value, f), d, 'day set correct');
equal(p.find('a.ui-state-active').text(), 15, 'day shown correct');
var clear = p.find('.editable-clear a:visible');
ok(clear.length, 'clear link shown');
//click clear
clear.click();
setTimeout(function() {
ok(!p.is(':visible'), 'popover closed');
equal(e.data('editable').value, null, 'null saved to value');
equal(e.text(), e.data('editable').options.emptytext, 'empty text shown');
e.remove();
start();
}, 500);
});
});