budibase icon indicating copy to clipboard operation
budibase copied to clipboard

Validation Error when uploading attachments with Handlebars

Open melohagan opened this issue 3 years ago • 4 comments

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"]} img-err-1 "

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

  1. Create a new table with attachment column
  2. Add form with upload file component
  3. Add a button with a Save Row action that saves the uploaded file to the attachment column of the table
  4. Upload a file and click the save button

melohagan avatar May 04 '22 09:05 melohagan

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.

aptkingston avatar May 04 '22 10:05 aptkingston

I tried using the form field directly and that does work well.

It is for those custom scenarios were it'll be an issue.

melohagan avatar May 04 '22 13:05 melohagan

This issue has been automatically marked as stale because it has not had recent activity.

stale[bot] avatar Jul 07 '22 06:07 stale[bot]

Affected me and @adamjdavies in #7157.

R2bEEaton avatar Aug 09 '22 10:08 R2bEEaton

This issue has been automatically marked as stale because it has not had recent activity.

stale[bot] avatar Oct 12 '22 09:10 stale[bot]