Skip to content

Commit 350b474

Browse files
ilucinduizendnegen
authored andcommitted
Fix enforcing minDate to allow null value (adopted-ember-addons#131)
1 parent c01463a commit 350b474

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

addon/mixins/pikaday.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export default Ember.Mixin.create({
111111

112112
// If the current date is lower than minDate we set date to minDate
113113
run.schedule('sync', () => {
114-
if (value < minDate) {
114+
if (value && value < minDate) {
115115
pikaday.setDate(minDate);
116116
}
117117
});

tests/integration/components/pikaday-input-test.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -415,4 +415,18 @@ test('if maxDate is lower than value we set pikaday\'s current date to maxDate',
415415

416416
this.set('maxDate', today);
417417
assert.equal(this.get('currentDate').getDate(), today.getDate(), 'value should change');
418-
});
418+
});
419+
420+
test('if value is null we don\'t enforce minDate or maxDate', function(assert) {
421+
assert.expect(1);
422+
423+
let today = new Date();
424+
let tomorrow = new Date( Date.now() + (60 * 60 * 24 * 1000));
425+
426+
this.set('currentDate', null);
427+
this.render(hbs`{{pikaday-input maxDate=maxDate minDate=minDate value=currentDate onSelection=(action (mut currentDate)) }}`);
428+
429+
run(() => this.set('maxDate', tomorrow));
430+
run(() => this.set('minDate', today));
431+
assert.equal(this.get('currentDate'), null, 'value should be null');
432+
});

0 commit comments

Comments
 (0)