Sha256: 2ca0c5706ee7bed35c9ea568f8393b34e16167ff7f04ee67a7771cc4bf953208
Contents?: true
Size: 1.29 KB
Versions: 31
Compression:
Stored size: 1.29 KB
Contents
import flatpickr from "flatpickr" export default function Datepicker(scope = document) { if (scope === "") { scope = document } else if (scope instanceof String) { scope = document.querySelectorAll(scope) } const datepickerInputs = scope.querySelectorAll("input[data-datepicker-type]") // Initializes the datepickers on the text inputs and sets the proper type // to enable browsers default datepicker if the current OS is iOS. if (Alchemy.isiOS) { datepickerInputs.forEach((input) => { input.attributes.type = input.dataset.datepickerType }) } else { datepickerInputs.forEach((input) => { const type = input.dataset.datepickerType const options = { // alchemy_i18n supports `zh_CN` etc., but flatpickr only has two-letter codes (`zh`) locale: Alchemy.locale.slice(0, 2), altInput: true, altFormat: Alchemy.t(`formats.${type}`), altInputClass: "flatpickr-input", enableTime: /time/.test(type), noCalendar: type === "time", time_24hr: Alchemy.t("formats.time_24hr"), onValueUpdate(_selectedDates, _dateStr, instance) { return Alchemy.setElementDirty( instance.element.closest(".element-editor") ) } } flatpickr(input, options) }) } }
Version data entries
31 entries across 31 versions & 1 rubygems