Error message for uniqueness validation in AutoTable
Is it possible to customize the error message ("Failed to add field!") that shows up when you add a new record that fails uniqueness validation?
I'm using errors.add per the docs:
https://tapestry-stitch.gadget.app/edit/dev-kalen/files/api/models/fieldMapping/validations/uniqueness.js?startLineNumber=31&startColumn=0&endLineNumber=32&endColumn=0
https://tapestry-stitch.gadget.app/edit/dev-kalen/logs?logql=%7Benvironment_id%3D%22468181%22%7D%20%7C%20json%20%7C%20level%3D~%22info%7Cwarn%7Cerror%22%20%7C%20trace_id%3D%2238c71f65b290d23c8954b0064f5620e9%22&timeRange%5Binput%5D=Last%205%20mins

5 Replies
Are you referring to the errors.add from useActionForm? I don't think that applies to autocomponents. Though, I think that you're able to write a custom message for errors. Have you taken a look at the
onFailure
prop of AutoForm? https://docs.gadget.dev/reference/react/auto#autoform-:~:text=on%20the%20backend-,onFailure%3F,-(error)%20%3D%3E%20voidLet me also talk to the team to see if there's another alternative
Oh oups! AutoTable! Let me dig some more
Could you please point me to the docs that you're referring to? I can't find anything about errors.add in the autotable docs, nor with the search.
Ahh, just found it. File validations
So if I'm understanding correctly, you've added a custom action on the AutoTable that adds a new record on the field model and want to display the error in the autotable toast
(sorry, was doing all this while we had the outage so I had to dig without access to the code you shared)
I was wondering why you don't use the uniqueness validation on the field (scoped by shop or whatever needed) which would return an error about uniqueness and would save you on request time
In AutoTable there currently doesn't exist a way to add custom action error handlers so the uniqueness validation is probably the best way to go.
we are using uniqueness validation - it's linked in my initial post
I think what Antoine is referring to is that you currently have a code snippet validation that checks for uniqueness. You can replace that code snippet field validation with our uniqueness field validation
As for the toast message content that you're seeing, that seems to be a hardcoded value that you have in your frontend code
^^^ This appears in your
web/routes/mappings._index.jsx
fileGot it my bad I mixed up my code validation with uniqueness becaues I named it uniqueness.js! In this case there are 3 fields needed for the uniqueness validation (shopId, resource, attribute)
So I guess in that case it's not possible to have a better error message?
oh wait sorry reading the rest of your message more carefully now
wow could have sworn I searched for the error message in my code base before posting here. One known issue I have in cursor (underlying vs code issue) is that sometimes certain files I haven't opened in a while aren't indexed for search. Have tried to resolve it a few times but not quite sure how. So if I forget to do a grep then I sometimes will think something doesn't exist in the codebase that actually does.
ok all set here thanks