Merge pull request #13865 from Budibase/BUDI-8316/cannot-save-time-value-to-internal-db
Fix time-only form fields for internal db
This commit is contained in:
commit
d225cde835
|
@ -68,6 +68,15 @@
|
||||||
maximum: schema?.constraints?.length?.maximum,
|
maximum: schema?.constraints?.length?.maximum,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
[FieldType.DATETIME]: (_field, schema) => {
|
||||||
|
const props = {
|
||||||
|
valueAsTimestamp: !schema?.timeOnly,
|
||||||
|
}
|
||||||
|
if (schema?.dateOnly) {
|
||||||
|
props.enableTime = false
|
||||||
|
}
|
||||||
|
return props
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const fieldSchema = getFieldSchema(field)
|
const fieldSchema = getFieldSchema(field)
|
||||||
|
|
|
@ -16,15 +16,37 @@
|
||||||
export let onChange
|
export let onChange
|
||||||
export let span
|
export let span
|
||||||
export let helpText = null
|
export let helpText = null
|
||||||
|
export let valueAsTimestamp = false
|
||||||
|
|
||||||
let fieldState
|
let fieldState
|
||||||
let fieldApi
|
let fieldApi
|
||||||
|
|
||||||
const handleChange = e => {
|
const handleChange = e => {
|
||||||
const changed = fieldApi.setValue(e.detail)
|
let value = e.detail
|
||||||
if (onChange && changed) {
|
if (timeOnly && valueAsTimestamp) {
|
||||||
onChange({ value: e.detail })
|
if (!isValidDate(value)) {
|
||||||
|
// Handle time only fields that are timestamps under the hood
|
||||||
|
value = timeToDateISOString(value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const changed = fieldApi.setValue(value)
|
||||||
|
if (onChange && changed) {
|
||||||
|
onChange({ value })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const isValidDate = value => !isNaN(new Date(value))
|
||||||
|
|
||||||
|
const timeToDateISOString = value => {
|
||||||
|
let [hours, minutes] = value.split(":").map(Number)
|
||||||
|
|
||||||
|
const date = new Date()
|
||||||
|
date.setHours(hours)
|
||||||
|
date.setMinutes(minutes)
|
||||||
|
date.setSeconds(0)
|
||||||
|
date.setMilliseconds(0)
|
||||||
|
return date.toISOString()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue