Skip to content

Commit

Permalink
dateui: clear button does not submit, fixes vitalets#374
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Oct 5, 2013
1 parent 0b929fe commit 0ef1ad5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
19 changes: 13 additions & 6 deletions src/inputs/dateui/dateui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

});
Expand Down
44 changes: 43 additions & 1 deletion test/unit/dateui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

});


});

0 comments on commit 0ef1ad5

Please sign in to comment.