diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 5ecb1d9..a8d55bf 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -4,7 +4,8 @@ X-editable changelog
Version 1.4.4 wip
----------------------------
-[bug #166] clear button forinput type = number (vitalets)
+[bug #171] clear in date & datetime when showbuttons=false (vitalets)
+[bug #166] clear button for input type=number (vitalets)
[bug] checklist don't show checked for single value (vitalets)
[enh #188] added bootstrap datetime (adeg, vitalets)
[bug] editable-poshytip on inline mode tries to write in $.Poshytip (vitalets)
diff --git a/src/inputs/date/date.js b/src/inputs/date/date.js
index b7b57a3..522836f 100644
--- a/src/inputs/date/date.js
+++ b/src/inputs/date/date.js
@@ -108,6 +108,9 @@ $(function(){
clear: function() {
this.$input.data('datepicker').date = null;
this.$input.find('.active').removeClass('active');
+ if(!this.options.showbuttons) {
+ this.$input.closest('form').submit();
+ }
},
autosubmit: function() {
diff --git a/src/inputs/datetime/datetime.js b/src/inputs/datetime/datetime.js
index 3155f76..da73e9d 100644
--- a/src/inputs/datetime/datetime.js
+++ b/src/inputs/datetime/datetime.js
@@ -132,6 +132,9 @@ $(function(){
clear: function() {
this.$input.data('datetimepicker').date = null;
this.$input.find('.active').removeClass('active');
+ if(!this.options.showbuttons) {
+ this.$input.closest('form').submit();
+ }
},
autosubmit: function() {
diff --git a/test/unit/date.js b/test/unit/date.js
index a7205f8..c4b1a09 100644
--- a/test/unit/date.js
+++ b/test/unit/date.js
@@ -148,7 +148,7 @@ $(function () {
ok(!p.is(':visible'), 'popover closed');
});
- asyncTest("clear button", function () {
+ asyncTest("clear button (showbuttons: true)", function () {
var d = '15.05.1984',
e = $(''+d+'').appendTo(fx).editable({
format: f,
@@ -189,5 +189,46 @@ $(function () {
}, timeout);
});
+
+
+ asyncTest("clear button (showbuttons: false)", function () {
+ var d = '15.05.1984',
+ e = $(''+d+'').appendTo(fx).editable({
+ format: f,
+ clear: 'abc',
+ showbuttons: false
+ });
+
+ $.mockjax({
+ url: 'post-date-clear1.php',
+ 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('.datepicker').is(':visible'), 'datepicker exists');
+
+ equal(frmt(e.data('editable').value, f), d, 'day set correct');
+ equal(p.find('td.day.active').text(), 15, 'day shown correct');
+
+ var clear = p.find('.editable-clear a');
+ equal(clear.text(), 'abc', '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();
+ }, timeout);
+
+ });
});
\ No newline at end of file
diff --git a/test/unit/datetime.js b/test/unit/datetime.js
index 2b86f87..4dcbccc 100644
--- a/test/unit/datetime.js
+++ b/test/unit/datetime.js
@@ -162,7 +162,7 @@ $(function () {
ok(!p.is(':visible'), 'popover closed');
});
- asyncTest("clear button", function () {
+ asyncTest("clear button (showbuttons: true)", function () {
var d = '15.05.1984 16:40',
e = $(''+d+'').appendTo(fx).editable({
format: f,
@@ -210,4 +210,49 @@ $(function () {
});
+
+ asyncTest("clear button (showbuttons: false)", function () {
+ var d = '15.05.1984 16:40',
+ e = $(''+d+'').appendTo(fx).editable({
+ format: f,
+ clear: 'abc'
+ });
+
+ $.mockjax({
+ url: 'post-datetime-clear1.php',
+ response: function(settings) {
+ equal(settings.data.value, '', 'submitted value correct');
+ }
+ });
+
+ equal(frmt(e.data('editable').value, 'dd.mm.yyyy hh:ii'), d, 'value correct');
+
+ e.click();
+ var p = tip(e);
+ ok(p.find('.datetimepicker').is(':visible'), 'datetimepicker exists');
+
+ equal(frmt(e.data('editable').value, f), d, 'day set correct');
+ equal(p.find('td.day.active').text(), 15, 'day shown correct');
+
+ var clear = p.find('.editable-clear a');
+ equal(clear.text(), 'abc', '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');
+
+ //reopen popover
+ e.click();
+ p = tip(e);
+ ok(p.find('.datetimepicker').is(':visible'), 'datetimepicker exists');
+
+ e.remove();
+ start();
+ }, timeout);
+
+ });
});
\ No newline at end of file