Skip to content

Commit c3ecc73

Browse files
committed
fix year entry for dates in forms
1 parent 7473c32 commit c3ecc73

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/widgets/forms/basic.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ export function basicField (
136136
;(field as any).style = inputStyle
137137
rhs.appendChild(field)
138138
field.setAttribute('type', params.type ? params.type : 'text')
139+
const fieldType = (field.getAttribute('type') || '').toLowerCase()
140+
const deferWhileFocused = fieldType === 'date' || fieldType === 'datetime-local'
139141

140142
const size = kb.anyJS(form, ns.ui('size')) || styleConstants.textInputSize || 20
141143
field.setAttribute('size', size)
@@ -189,9 +191,13 @@ export function basicField (
189191
field.addEventListener(
190192
'change',
191193
function (_e) {
194+
if (deferWhileFocused && dom.activeElement === field) return
192195
// i.e. lose focus with changed data
193196
if (params.pattern && !field.value.match(params.pattern)) return
194-
field.disabled = true // See if this stops getting two dates from fumbling e.g the chrome datepicker.
197+
const disabledForSave = !deferWhileFocused
198+
if (disabledForSave) {
199+
field.disabled = true // See if this stops getting two dates from fumbling e.g the chrome datepicker.
200+
}
195201
field.setAttribute('style', inputStyle + 'color: gray;') // pending
196202
const ds = kb.statementsMatching(subject, property as any) // remove any multiple values
197203
let result
@@ -255,7 +261,9 @@ export function basicField (
255261
updateMany(ds, is as any, function (uri, ok, body) {
256262
// kb.updater.update(ds, is, function (uri, ok, body) {
257263
if (ok) {
258-
field.disabled = false
264+
if (disabledForSave) {
265+
field.disabled = false
266+
}
259267
field.setAttribute('style', inputStyle)
260268
} else {
261269
box.appendChild(errorMessageBlock(dom, body))

0 commit comments

Comments
 (0)