Skip to content

Commit 0545b38

Browse files
committed
Add support for clearDate event.
Also add tests for clearDate and changeDate actions to ensure that both work correctly when the date value of the datepicker is cleared or changed.
1 parent 7c53cf0 commit 0545b38

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

addon/components/datepicker-support.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ export default Ember.Mixin.create({
5353
}).
5454
on('focusin', function(event) {
5555
self.sendAction('focus-in', self, event);
56+
}).
57+
on('clearDate', function(event) {
58+
Ember.run(function() {
59+
self._didChangeDate(event);
60+
});
5661
});
5762

5863
this._updateDatepicker();
@@ -79,7 +84,11 @@ export default Ember.Mixin.create({
7984

8085
this.set('mustUpdateInput', false);
8186
this.set('value', value);
82-
this.sendAction('changeDate', value);
87+
if (event.type === 'clearDate') {
88+
this.sendAction('clearDate');
89+
} else {
90+
this.sendAction('changeDate', value);
91+
}
8392
},
8493

8594
_addObservers: Ember.on('didInsertElement', function() {

tests/integration/components/bootstrap-datepicker-integration-test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,44 @@ test('triggers specified action on focusin event', function (assert) {
3939

4040
assert.ok(actionIsTriggered, 'action is triggered on focusin');
4141
});
42+
43+
test('triggers changeDate action when date selection changes', function(assert) {
44+
assert.expect(1);
45+
46+
this.set('myDate', null);
47+
48+
var actionIsTriggered = false;
49+
this.on('myAction', () => {
50+
actionIsTriggered = true;
51+
});
52+
53+
this.render(hbs`
54+
{{bootstrap-datepicker value=myDate changeDate="myAction"}}
55+
`);
56+
57+
var input = this.$('input.ember-text-field');
58+
input.datepicker('setDate', new Date());
59+
60+
assert.ok(actionIsTriggered, 'action is triggered');
61+
});
62+
63+
test('triggers clearDate action when date selection is cleared', function(assert) {
64+
assert.expect(1);
65+
66+
this.set('myDate', new Date());
67+
68+
var actionIsTriggered = false;
69+
this.on('myAction', () => {
70+
actionIsTriggered = true;
71+
});
72+
73+
this.render(hbs`
74+
{{bootstrap-datepicker value=myDate clearDate="myAction"}}
75+
`);
76+
77+
var input = this.$('input.ember-text-field');
78+
input.datepicker('setDate', null);
79+
80+
assert.ok(actionIsTriggered, 'action is triggered');
81+
});
82+

0 commit comments

Comments
 (0)