Skip to content

Commit

Permalink
feat(datepicker): allow min and max limits
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximBalaganskiy committed Jun 17, 2019
1 parent 9f2c0ee commit 31d5593
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/elements/datepicker/datepicker.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
<label for="${controlId}" ref="labelElement">${label}</label>
<i ref="icon" class="material-icons opener" click.delegate="open()">today</i>
</div>
<md-datepicker view-model.ref="mdDatepicker" container="body" year-range.bind="yearRange" type="date" hidden disabled readonly tabindex="-1" value.bind="value" change.delegate="suppressMaterializeChange($event)"></md-datepicker>
<md-datepicker view-model.ref="mdDatepicker" container="body" year-range.bind="yearRange" type="date" hidden disabled
readonly tabindex="-1" value.bind="value" change.delegate="suppressMaterializeChange($event)"
min-date.bind="minDate" max-date.bind="maxDate"></md-datepicker>
</template>
12 changes: 12 additions & 0 deletions src/elements/datepicker/datepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,25 @@ export class Datepicker {
@au.bindable({ defaultBindingMode: au.bindingMode.oneTime })
yearRange: number | number[];

@au.bindable({ defaultBindingMode: au.bindingMode.oneTime })
minDate: Date;

@au.bindable({ defaultBindingMode: au.bindingMode.oneTime })
maxDate: Date;

labelElement: HTMLLabelElement;

@au.bindable({ defaultBindingMode: au.bindingMode.twoWay })
value: Date;
valueChanged() {
au.fireEvent(this.element, "change");
au.fireEvent(this.element, "blur");
if (this.minDate && this.value < this.minDate) {
this.value = this.minDate;
}
if (this.maxDate && this.value > this.maxDate) {
this.value = this.maxDate;
}
this.taskQueue.queueTask(() => au.updateLabel(this.input, this.labelElement));
}

Expand Down

0 comments on commit 31d5593

Please sign in to comment.