Skip to content

Commit

Permalink
Merge pull request #2511 from sascha-karnatz/remove-ios-switch-on-dat…
Browse files Browse the repository at this point in the history
…a-pickers

Remove iOS switch for data pickers
  • Loading branch information
tvdeyen authored Jul 3, 2023
2 parents 0b1ceaf + 211c5f8 commit 38af3ff
Showing 1 changed file with 20 additions and 27 deletions.
47 changes: 20 additions & 27 deletions app/javascript/alchemy_admin/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,25 @@ export default function Datepicker(scope = document) {

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",
dateFormat: "Z",
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")
)
}
// Initializes the datepickers
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",
dateFormat: "Z",
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)
})
}
}
flatpickr(input, options)
})
}

0 comments on commit 38af3ff

Please sign in to comment.