recordForm now produces selects

This commit is contained in:
Michael Shanks 2020-02-27 22:06:53 +00:00
parent 4c5654594e
commit 0b3c62d426
1 changed files with 14 additions and 0 deletions

View File

@ -32,6 +32,10 @@ const heading = record => ({
const field = (record, f) => {
if (f.type === "bool") return checkbox(record, f)
if (f.type === "string"
&& f.typeOptions
&& f.typeOptions.values
&& f.typeOptions.values.length > 0) return select(record, f)
return textField(record, f)
}
@ -54,6 +58,16 @@ const checkbox = (record, f) => ({
checked: fieldValueBinding(record, f),
})
const select = (record, f) => ({
_component: "@budibase/standard-components/select",
value: fieldValueBinding(record, f),
_children: f.typeOptions.values.map(val => ({
_component: "@budibase/standard-components/option",
value: val,
text: val
}))
})
const fieldValueBinding = (record, f) => `state.${record.name}.${f.name}`
const capitalize = s => s.charAt(0).toUpperCase() + s.slice(1)