imaskjs
imaskjs copied to clipboard
Can't key in week number 01 with moment.js
Describe the bug
Can't key in week 202201, but it works for 202202, 202203... and 202253.
To Reproduce codepen
Expected behavior Should able to key in week 01.
FWIW, I found if change format toYYYY/WW
, no this bug anymore, but isoweek is not I wanted. Thank you!
Environment:
- OS: MacOS
- Browser Chrome
- Version 100.0.4897.75
- IMask 6.4.2
- moment 2.29.2
I made a workaround
const element = document.querySelector('#input-weeknum')
const momentFormat = 'YYYY-ww'
const blocksMask = IMask(element, {
mask: 'ye\\ar {2\\0}YY / week MM',
lazy: false, // make placeholder always visible
blocks: {
YY: {
mask: '00'
},
MM: {
mask: '00'
}
},
validate (_, masked) {
const v = masked.unmaskedValue
if (v.length === 6) {
const date = moment(v, momentFormat)
log.debug(date)
return date._isValid
} else {
return true
}
}
})