Add on change action to S3 upload field

This commit is contained in:
Andrew Kingston 2022-04-14 10:04:38 +01:00
parent 67f94e0cae
commit 892088702f
2 changed files with 65 additions and 48 deletions

View File

@ -2876,6 +2876,62 @@
} }
] ]
}, },
"s3upload": {
"name": "S3 File Upload",
"info": "This component can't be used with S3 datasources that use custom endpoints.",
"icon": "UploadToCloud",
"styles": ["size"],
"editable": true,
"settings": [
{
"type": "field/attachment",
"label": "Field",
"key": "field"
},
{
"type": "text",
"label": "Label",
"key": "label"
},
{
"type": "dataSource/s3",
"label": "S3 Datasource",
"key": "datasourceId"
},
{
"type": "text",
"label": "Bucket",
"key": "bucket"
},
{
"type": "text",
"label": "File Name",
"key": "key"
},
{
"type": "event",
"label": "On change",
"key": "onChange",
"context": [
{
"label": "Field Value",
"key": "value"
}
]
},
{
"type": "boolean",
"label": "Disabled",
"key": "disabled",
"defaultValue": false
},
{
"type": "validation/attachment",
"label": "Validation",
"key": "validation"
}
]
},
"dataprovider": { "dataprovider": {
"name": "Data Provider", "name": "Data Provider",
"info": "Pagination is only available for data stored in tables.", "info": "Pagination is only available for data stored in tables.",
@ -3707,51 +3763,6 @@
} }
] ]
}, },
"s3upload": {
"name": "S3 File Upload",
"info": "This component can't be used with S3 datasources that use custom endpoints.",
"icon": "UploadToCloud",
"styles": ["size"],
"editable": true,
"settings": [
{
"type": "field/attachment",
"label": "Field",
"key": "field"
},
{
"type": "text",
"label": "Label",
"key": "label"
},
{
"type": "dataSource/s3",
"label": "S3 Datasource",
"key": "datasourceId"
},
{
"type": "text",
"label": "Bucket",
"key": "bucket"
},
{
"type": "text",
"label": "File Name",
"key": "key"
},
{
"type": "boolean",
"label": "Disabled",
"key": "disabled",
"defaultValue": false
},
{
"type": "validation/attachment",
"label": "Validation",
"key": "validation"
}
]
},
"markdownviewer": { "markdownviewer": {
"name": "Markdown Viewer", "name": "Markdown Viewer",
"icon": "TaskList", "icon": "TaskList",

View File

@ -10,6 +10,7 @@
export let label export let label
export let disabled = false export let disabled = false
export let validation export let validation
export let onChange
let fieldState let fieldState
let fieldApi let fieldApi
@ -88,6 +89,13 @@
} }
} }
const handleChange = e => {
fieldApi.setValue(e.detail)
if (onChange) {
onChange({ value: e.detail })
}
}
onMount(() => { onMount(() => {
uploadStore.actions.registerFileUpload($component.id, upload) uploadStore.actions.registerFileUpload($component.id, upload)
}) })
@ -113,9 +121,7 @@
value={fieldState.value} value={fieldState.value}
disabled={loading || fieldState.disabled} disabled={loading || fieldState.disabled}
error={fieldState.error} error={fieldState.error}
on:change={e => { on:change={handleChange}
fieldApi.setValue(e.detail)
}}
{processFiles} {processFiles}
{handleFileTooLarge} {handleFileTooLarge}
maximum={1} maximum={1}