Skip to content
This repository was archived by the owner on Dec 26, 2019. It is now read-only.

Commit 93538a4

Browse files
committed
Reset date value when input field is cleared.
Listen to the input event and check if the input field is cleared. If yes, set the value to null.
1 parent 0fb4000 commit 93538a4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

addon/components/datepicker-support.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ export default Ember.Mixin.create({
3939
Ember.run(function() {
4040
self._didChangeDate(event);
4141
});
42+
}).
43+
on('input', function() {
44+
if (!self.$().val()) {
45+
self.set('value', null);
46+
}
4247
});
4348

4449
this._updateDatepicker();

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ test('should display date with default format when no format is set', function(a
3030
assert.equal(this.$().val(), '12/31/2014');
3131
});
3232

33+
test('should reset date when input is cleared', function(assert) {
34+
assert.expect(2);
35+
36+
this.subject({
37+
value: new Date(2014, 11, 31)
38+
});
39+
40+
assert.ok(this.$().datepicker('getDate'), 'initial value is set');
41+
42+
this.$().val('');
43+
this.$().trigger('input');
44+
45+
assert.equal(this.$().datepicker('getDate'), null, 'value is reset when input is cleared');
46+
});
47+
3348
test('should display date with custom format when format is set', function(assert) {
3449
assert.expect(1);
3550

0 commit comments

Comments
 (0)