5 Replies
Chocci_Milk
Chocci_Milk3mo ago
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%20void
Chocci_Milk
Chocci_Milk3mo ago
Let 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.
kalenjordan
kalenjordanOP3mo ago
we are using uniqueness validation - it's linked in my initial post
Millan
Millan3mo ago
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
try{
// Trying to create a record. Throws error when not unique
} catch (e){
app.toast.show("Failed to add field!", { isError: true });
}
try{
// Trying to create a record. Throws error when not unique
} catch (e){
app.toast.show("Failed to add field!", { isError: true });
}
^^^ This appears in your web/routes/mappings._index.jsx file
kalenjordan
kalenjordanOP3mo ago
Got 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

Did you find this page helpful?