budibase
budibase copied to clipboard
Validation Error when uploading attachments with Handlebars
Discussed in https://github.com/Budibase/budibase/discussions/5695
Originally posted by newtonlaw95 May 3, 2022
I am getting an validation error when saving an attachment to the row "validationErrors: {image: ["must be of type array"]}
"
You can see that the screenshot is showing the array being sent as a string. I was able to recreate this, and also resolve it by using JavaScript instead e.g. return $("attachment_field")
Steps
- Create a new table with attachment column
- Add form with upload file component
- Add a button with a Save Row action that saves the uploaded file to the attachment column of the table
- Upload a file and click the save button
I'm wondering why this needs to be a binding at all - can you not just use the form field directly? I mean that you don't need to add a custom field to the save row action - just link the attachment field to the field in the table schema and you don't need any bindings, and I think this should work just fine.
If it does need to be a binding for some reason (like if you need to name your attachment field something different than the the table attachment column name) then using the literal helper would parse this as a real array. So something like {{ literal form.fields.attachment_field }}. HBS parses everything as a string which is where this issue comes from. JS uses real types as you discovered so that also works.
I tried using the form field directly and that does work well.
It is for those custom scenarios were it'll be an issue.
This issue has been automatically marked as stale because it has not had recent activity.
Affected me and @adamjdavies in #7157.
This issue has been automatically marked as stale because it has not had recent activity.