Limit attachment on forms
This commit is contained in:
parent
6ca25d400a
commit
fdf83fd65d
1 changed files with 32 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import BlockComponent from "components/BlockComponent.svelte"
|
import BlockComponent from "components/BlockComponent.svelte"
|
||||||
|
import { FieldType } from "@budibase/types"
|
||||||
|
|
||||||
export let field
|
export let field
|
||||||
export let schema
|
export let schema
|
||||||
|
@ -21,12 +22,20 @@
|
||||||
bb_reference: "bbreferencefield",
|
bb_reference: "bbreferencefield",
|
||||||
}
|
}
|
||||||
|
|
||||||
const getComponentForField = field => {
|
const getFieldSchema = field => {
|
||||||
const fieldSchemaName = field.field || field.name
|
const fieldSchemaName = field.field || field.name
|
||||||
if (!fieldSchemaName || !schema?.[fieldSchemaName]) {
|
if (!fieldSchemaName || !schema?.[fieldSchemaName]) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const type = schema[fieldSchemaName].type
|
return schema[fieldSchemaName]
|
||||||
|
}
|
||||||
|
|
||||||
|
const getComponentForField = field => {
|
||||||
|
const fieldSchema = getFieldSchema(field)
|
||||||
|
if (!fieldSchema) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
const { type } = fieldSchema
|
||||||
return FieldTypeToComponentMap[type]
|
return FieldTypeToComponentMap[type]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +50,29 @@
|
||||||
placeholder: field.name,
|
placeholder: field.name,
|
||||||
_instanceName: field.name,
|
_instanceName: field.name,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fieldProps = {
|
||||||
|
...getPropsByType(field),
|
||||||
|
...fieldProps,
|
||||||
|
}
|
||||||
return fieldProps
|
return fieldProps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPropsByType(field) {
|
||||||
|
const propsMapByType = {
|
||||||
|
[FieldType.ATTACHMENT]: (_field, schema) => {
|
||||||
|
return {
|
||||||
|
maximum: schema?.constraints?.length?.maximum,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const fieldSchema = getFieldSchema(field)
|
||||||
|
const mapper = propsMapByType[fieldSchema.type]
|
||||||
|
if (mapper) {
|
||||||
|
return mapper(field, fieldSchema)
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if getComponentForField(field) && field.active}
|
{#if getComponentForField(field) && field.active}
|
||||||
|
|
Loading…
Reference in a new issue