displaying field level validation errors from the backend

Hi, My backend returns validation structured validation errors on post or put, with field level error information for example:
{
"modelState": {
"name": "validate error"
},
"message": "Name: validate error"
}
{
"modelState": {
"name": "validate error"
},
"message": "Name: validate error"
}
How can I get the error for the name field to display next to the name field in refine. Is there a specific exception error structure I need to use?
S
sensitive-blue•457d ago
A
automatic-azure•457d ago
Thanks for getting back to me, I've read the article and I can't find in it what I want looking for. I was hoping for a structure of an exception I as a dataProvider can throw in the create or update that'll be handled by refine to display the error correctly next to the field.
S
sensitive-blue•457d ago
@noam.honig Im so sorry. I sent you wrong link 😦 https://refine.dev/docs/api-reference/core/providers/data-provider/#error-format this is the correct one
A
automatic-azure•457d ago
Thanks for that. In that error, how do I specify the exact error text I want to display next to each field? Something like:
{
message:"something is wrong",
statusCode:500,
errors:{
name:"Too Short",
age:"Too Young"
}
}
{
message:"something is wrong",
statusCode:500,
errors:{
name:"Too Short",
age:"Too Young"
}
}
S
sensitive-blue•457d ago
Which form library u are using ?
A
automatic-azure•457d ago
I'm using the default one used in the tutorial
S
sensitive-blue•457d ago
which tutorial ?
S
sensitive-blue•457d ago
you can write custom form validation and error message like this https://refine.dev/docs/advanced-tutorials/forms/custom-form-validation/
A
automatic-azure•457d ago
I see - I was hoping for something built in refine that standardizes that as well
S
sensitive-blue•457d ago
🙏 we will release refine 4 in 1 or 2 month. we will definitely consider this Hi @noam.honig, We discussed in the core team. We think your point is really valuable. Thank you 🙏 Do you wanna open feature request on Github ? If you open, we try to speed things up.
A
automatic-azure•457d ago
Sounds good
O
Omer•457d ago
Remult looks great, congrats 🙂 Are you creating a dataprovider?
A
automatic-azure•457d ago
Hi @Omer, yes I'm creating a data provider, it seems fairly simple and powerful @Omer Since you mentioned remult, I would like to ask a follow-up question if that's ok. In remult I have a lot of metadata around the entities (field types, captions, validations etc...) This opens up the opportunity to create a powerful inferer that'll be based on entity metadata rather than JSON results. Is there a simple api for me to use to provide metadata to the refine inferer or do I need to create multiple inferers of my own?
O
Omer•457d ago
@aliemirs can you help?
C
correct-apricot•457d ago
Hey @noam.honig, we have a createInferencer function in inferencer package that we use to create all of the inferencer components for our UI integrations. We're simply testing the response data fields by set of functions and send them to the renderer function which maps them and generates the code you see and able to copy. If you want to give it a try, you can also pass fieldTransformers array and customElements array in types FieldTransformer[] and FieldInferencer[] so you can provide custom types of fields to renderer and in that function you can generate the code for those types. You can try to experiment with it by using the codebase and by using the createInferencer function 🚀 Hope this helps 🙏
A
automatic-azure•456d ago
Can you provide some example usage of the createInferencer function - something where I provide to it the field names, captions and types and it'll render accordingly? I'm looking for a starter point I've played with the fieldTransformer property of the MUIInferer - but I was looking for a way to tell the Inferer which fields I have. I know the fields and their types and I don't want it to be inferred by the json result - I want it to also work when there are no rows at all @aliemirs (sorry, I forgot to mention you in my previous messages that were intended for you )
C
correct-apricot•455d ago
Got it @noam.honig, currently there's no way for it but I think you got the idea about how the inferencer works. We can modify the createInferencer to accept fields array and use it as the inffered fields. And for your case, you can then create a wrapper around it and determine the fields by your schema 🤔 Do you think this will work for you?
A
automatic-azure•455d ago
I think so, and I also think it could be useful for other inferers that you may want to create - infer from open api, infer from graphql etc...
C
correct-apricot•454d ago
Hey @noam.honig can you open a feature request issue on GitHub? We'll add this to our to-do and hopefully do a release soon 🙏
A
automatic-azure•453d ago
@aliemirs so far I've been only playing with refine - I don't want to open an issue that'll require your resources, before I have an actual use case
More Posts
Custom ID in tableHi, I have a table that have a unique ID column that isn't "id", as DatGrid expects. I'm getting an Load category data one by oneHi, My post object has a category id, and on the table, I want to display the category name. I havCreate projects with javascriptHello everyone, I wanted to know how I can create a project in JavaScript with this command: `npm crcreate-refine-app with yarn v3just going through the getting started tutorial, and finding that the install using `npm` is workingResource Primary KeyIs there a way to define the row which is used as primary key on any given resource? In some cases, How to deal with nested resources?Hi! What is the best practice to have nested resources? For exmaple: There is a Organization which hUpdate related objectsHi there, I’m looking for a way to update nested objects using Refine. Did not yet settle on a dataupdate switch on api responseHello !! I'm currently using refine to make an app and i have a from in which i set every field witCatch 401 errorHi, how can i catch a 401 error and redirect to a specific page, by default it goes to the login pagrefetch useTable dataHi guys! can we use any method to refetch data in useTable hook?DataGrid sorting not workHi! I would like to implement the sorting in my DataGrid and I did that : ```ts const {dataGridProHow can we designate the application port?This project will be running in a monorepo with a bunch of applications and 3000 is already taken. IMy components not showingI have made some components but they are not visible on home page. The only output I am seeing is(imCan't use other locale on DateFields from InferencerFor example, I'm building an app with Mantine. The docs says this: https://refine.dev/docs/api-referI need to add certificate to useCustomI have a refine application. The url of backend include 443 port. Error: ERR_CERT_AUTHORITY_INVALIDAntd table expandable component doesn't stop network request although it's not on the view.I have created an antd table expandable component and when I expand it works as expected, but when IDynamic ErrorsHow to handle dynamic errors in useForm in onMutationError(error){ } the error conatins lot of daTesting Table ComponentHi everyone - I feel like I've scrubbed the internet to figure out this issues; apologies if this isI need to create a Create and an Edit page for a resource with a Many to Many relationshipsHello everyone, I am looking to create a Create and an Edit page for a resource with a many-to-many 404 after logging inWhy does refine application show a 404 after signing in? I have a custom auth provider(keycloak.js)