Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove iOS switch for data pickers #2511

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
}