Skip to content

Commit

Permalink
enhancement(Datepicker) implemented date format rendering in supporti…
Browse files Browse the repository at this point in the history
…ng text field if present materializecss#558
  • Loading branch information
gselderslaghs committed Dec 27, 2024
1 parent 4f5c37a commit ae8a06a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/datepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,10 @@ export class Datepicker extends Component<DatepickerOptions> {
this.el.classList.add('datepicker-date-input');
}

if (this.el.parentElement.querySelector('.datepicker-format') !== undefined) {
this._renderDateInputFormat(this.el);
}

if (this.options.isDateRange) {
if (!this.options.dateRangeEndEl) {
this.endDateEl = this.createDateInput();
Expand All @@ -450,6 +454,9 @@ export class Datepicker extends Component<DatepickerOptions> {
console.warn('Specified date range end input element in dateRangeEndEl not found');
} else {
this.endDateEl = document.querySelector(this.options.dateRangeEndEl) as HTMLInputElement;
if (this.endDateEl.parentElement.querySelector('.datepicker-format') !== undefined) {
this._renderDateInputFormat(this.endDateEl);
}
}
}

Expand All @@ -472,6 +479,13 @@ export class Datepicker extends Component<DatepickerOptions> {
}
}

/**
* Renders the date input format
*/
_renderDateInputFormat(el: HTMLInputElement) {
el.parentElement.querySelector('.datepicker-format').innerHTML = this.options.format.toString();
}

/**
* Gets a string representation of the given date.
*/
Expand Down

0 comments on commit ae8a06a

Please sign in to comment.