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

Commit f369eb9

Browse files
committed
Merge pull request #35 from octronic/reset-date-when-input-is-cleared
Reset date value when input field is cleared.
2 parents de53395 + 93538a4 commit f369eb9

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
@@ -40,6 +40,11 @@ export default Ember.Mixin.create({
4040
Ember.run(function() {
4141
self._didChangeDate(event);
4242
});
43+
}).
44+
on('input', function() {
45+
if (!self.$().val()) {
46+
self.set('value', null);
47+
}
4348
});
4449

4550
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)