1
0
Fork 0
mirror of synced 2024-09-20 11:27:56 +12:00
budibase/packages/builder/src/helpers/formFields.js
Andrew Kingston f2b12bcf45 Component error state improvements (#10136)
* Tidy logic for creating initial component instances

* Add initial implementation of enriching empty settings

* Fix regression that prevented custom placeholders from working (#9994)

* Tidy up

* Add automatic naming of form fields when added

* Update missing required setting placeholder

* Improve error states and add ability to automatically wrap a component in a required parent type

* Fix crash in column editor and rename component placeholder to error state

* Select the parent component after adding it when wrapping a component with a missing ancestor

* Fix blocks and make fields require forms

* Improve empty component placeholder

* Lint
2023-03-28 21:11:33 +01:00

32 lines
1 KiB
JavaScript

import { findClosestMatchingComponent } from "builderStore/componentUtils"
import {
getDatasourceForProvider,
getSchemaForDatasource,
} from "builderStore/dataBinding"
export const getComponentFieldOptions = (asset, id, type, loose = true) => {
const form = findClosestMatchingComponent(
asset,
id,
component => component._component === "@budibase/standard-components/form"
)
const datasource = getDatasourceForProvider(asset, form)
const schema = getSchemaForDatasource(asset, datasource, {
formSchema: true,
}).schema
// Get valid types for this field
let types = [type]
if (loose) {
if (type === "field/options" || type === "field/longform") {
// Allow options and longform to be used on string fields as well
types = [type, "field/string"]
}
}
types = types.map(type => type.slice(type.indexOf("/") + 1))
// Find fields of valid types
return Object.entries(schema || {})
.filter(entry => types.includes(entry[1].type))
.map(entry => entry[0])
}