mirror of
https://gitlab.com/bramw/baserow.git
synced 2024-11-21 23:37:55 +00:00
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
export function getPrefills(query) {
|
|
return Object.keys(query).reduce((prefills, key) => {
|
|
if (key.startsWith('prefill_')) {
|
|
const keyFormatted = key
|
|
.replace('prefill_', '') // Remove the prefix
|
|
.replaceAll('+', ' ') // Replace + with spaces
|
|
.toLowerCase()
|
|
let valueChosen = query[key]
|
|
if (Array.isArray(query[key])) {
|
|
valueChosen = valueChosen[valueChosen.length - 1]
|
|
}
|
|
prefills[keyFormatted] = valueChosen
|
|
}
|
|
return prefills
|
|
}, Object.create(null))
|
|
}
|
|
|
|
export function prefillField(formField, prefills) {
|
|
let prefill = prefills[formField.name.toLowerCase()]
|
|
if (prefill === undefined) {
|
|
prefill = prefills[formField.field.name.toLowerCase()]
|
|
if (prefill === undefined) {
|
|
prefill = prefills[`field_${formField.field.id}`]
|
|
}
|
|
}
|
|
return prefill
|
|
}
|
|
|
|
export function getHiddenFieldNames(query) {
|
|
return Object.keys(query)
|
|
.filter((key) => {
|
|
return key.startsWith('hide_')
|
|
})
|
|
.map((key) => {
|
|
return key.replace('hide_', '').replaceAll('+', ' ')
|
|
})
|
|
}
|