Skip to content
12 changes: 10 additions & 2 deletions src/widgets/forms/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ export function basicField (
;(field as any).style = inputStyle
rhs.appendChild(field)
field.setAttribute('type', params.type ? params.type : 'text')
const fieldType = (field.getAttribute('type') || '').toLowerCase()
const deferWhileFocused = fieldType === 'date' || fieldType === 'datetime-local'

const size = kb.anyJS(form, ns.ui('size')) || styleConstants.textInputSize || 20
field.setAttribute('size', size)
Expand Down Expand Up @@ -189,9 +191,13 @@ export function basicField (
field.addEventListener(
'change',
function (_e) {
if (deferWhileFocused && dom.activeElement === field) return
// i.e. lose focus with changed data
Comment thread
SharonStrats marked this conversation as resolved.
if (params.pattern && !field.value.match(params.pattern)) return
field.disabled = true // See if this stops getting two dates from fumbling e.g the chrome datepicker.
const disabledForSave = !deferWhileFocused
if (disabledForSave) {
field.disabled = true // See if this stops getting two dates from fumbling e.g the chrome datepicker.
Comment thread
SharonStrats marked this conversation as resolved.
Outdated
Comment thread
timea-solid marked this conversation as resolved.
Outdated
}
Comment thread
SharonStrats marked this conversation as resolved.
field.setAttribute('style', inputStyle + 'color: gray;') // pending
const ds = kb.statementsMatching(subject, property as any) // remove any multiple values
let result
Expand Down Expand Up @@ -255,7 +261,9 @@ export function basicField (
updateMany(ds, is as any, function (uri, ok, body) {
// kb.updater.update(ds, is, function (uri, ok, body) {
if (ok) {
field.disabled = false
if (disabledForSave) {
field.disabled = false
}
field.setAttribute('style', inputStyle)
} else {
box.appendChild(errorMessageBlock(dom, body))
Expand Down
Loading