<h4>Datepicker</h4>
<p>Attached to a field with the format specified via options.</p>
<input type="text" class="js-datepicker" value="02-12-1989" data-min="1989-02-12" data-max="2019-03-25">
<h4>Datepicker</h4>
<p>Attached to a field with the format specified via options.</p>
<input type="text" class="js-datepicker" value="02-12-1989"
data-min="1989-02-12"
data-max="2019-03-25"
>
/* No context defined for this component. */
import * as Pikaday from 'pikaday';
class Datepicker {
constructor(element) {
new Pikaday({
field: element,
format: 'd-m-Y',
minDate: new Date(element.dataset.min),
maxDate: new Date(element.dataset.max),
toString(date) {
// you should do formatting based on the passed format,
// but we will just return 'D/M/YYYY' for simplicity
const day = date.getDate();
const month = date.getMonth() + 1;
const year = date.getFullYear();
return `${day}-${month}-${year}`;
},
parse(dateString) {
// dateString is the result of `toString` method
const parts = dateString.split('-');
const day = parseInt(parts[0], 10);
const month = parseInt(parts[1], 10) - 1;
const year = parseInt(parts[2], 10);
return new Date(year, month, day);
},
i18n: {
previousMonth: 'Vorheriger Monat',
nextMonth: 'Nächsten Monat',
months: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
weekdays: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
weekdaysShort: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
},
});
}
}
export default Datepicker;
There are no notes for this item.