murph-skeleton/assets/js/admin/modules/datepicker.js

27 lines
559 B
JavaScript
Raw Normal View History

2021-03-24 12:27:07 +01:00
const Datepicker = require('vanillajs-datepicker')
const isDateSupported = () => {
2021-06-15 14:16:07 +02:00
const input = document.createElement('input')
const value = 'a'
2021-03-24 12:27:07 +01:00
2021-06-15 14:16:07 +02:00
input.setAttribute('type', 'date')
input.setAttribute('value', value)
2021-03-24 12:27:07 +01:00
2021-06-15 14:16:07 +02:00
return input.value !== value
2021-03-24 12:27:07 +01:00
}
module.exports = () => {
2021-06-15 14:16:07 +02:00
if (isDateSupported()) {
return
}
2021-03-24 12:27:07 +01:00
2021-06-15 14:16:07 +02:00
const inputs = document.querySelectorAll('input[type="date"]')
const size = inputs.length
2021-03-24 12:27:07 +01:00
2021-06-15 14:16:07 +02:00
for (let i = 0, c = inputs.length; i < c; i++) {
new Datepicker.Datepicker(inputs[i], {
format: 'yyyy-mm-dd'
})
}
2021-03-24 12:27:07 +01:00
}