Git Product home page Git Product logo

Comments (13)

edorivai avatar edorivai commented on April 20, 2024 3

I could be mistaken, but as far as I can see, field level validation does not handle asynchronous validation. Is that correct?

When I pass an async function (or a function which returns a Promise), AOR complains about the validation error not being a React node:

Failed prop type: Invalid prop `errorText` supplied to `TextField`, expected a ReactNode.
    in TextField (created by TextInput)
    in TextInput (created by ConnectedField)
Uncaught Error: Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of `TextField`.

Redux form supports an asyncValidation function, is there a way we can declare asyncValidation in our Create or Update components?

from react-admin.

shakdoesgithub avatar shakdoesgithub commented on April 20, 2024 3

@edorivai well I got it working... on field level...
here is the example :
<SimpleForm asyncValidate={asyncValidate} asyncBlurFields={[ 'firstName' ]}> <TextInput source="firstName" /> </SimpleForm>

You pass in the asyncValidate to the Form component, and the asyncBlurFields you pass in the fields that will trigger the asyncValidation.

from react-admin.

isaac-peka avatar isaac-peka commented on April 20, 2024 1

Also experiencing the same issue as @edorivai

from react-admin.

fzaninotto avatar fzaninotto commented on April 20, 2024

Admin-on-rest relies on redux-form for form validation, and redux-for supports asynchronous validation. So in theory it's not hard to do.

Until we implement it, feel free to use your own <Edit> or <Create> component.

from react-admin.

demetriusnunes avatar demetriusnunes commented on April 20, 2024

+1 for async validation support.

If the validation functions could return Promises to indicate async validation, that would be a simple and effective enough API.

from react-admin.

fzaninotto avatar fzaninotto commented on April 20, 2024

Fixed by #420

from react-admin.

edorivai avatar edorivai commented on April 20, 2024

As for as I know, async validation does not work at the field level, but there is a way to hook into the global async validation. See the tip at: https://marmelab.com/admin-on-rest/CreateEdit.html#global-validation

The gist is:

<TabbedForm asyncValidate={yourCustomAsyncValidationFunction}>
    ...
</TabbedForm>

from react-admin.

shakdoesgithub avatar shakdoesgithub commented on April 20, 2024

having the same issue as @edorivai and @sampeka.
when you pass asyncValidate function to the validate prop, it returns a promise.
How do we pass the fulfilled result to the redux-form?

from react-admin.

anewcoder1992 avatar anewcoder1992 commented on April 20, 2024

@fzaninotto now In the react 3.0 whether to support async validation?now did not use redux-form.so ,can async validation of server be realized?

from react-admin.

fzaninotto avatar fzaninotto commented on April 20, 2024

I suppose, since you can pass whatever props you want to the SimpleForm and they'll get passed to the react-final-form. I invite you to try!

from react-admin.

anewcoder1992 avatar anewcoder1992 commented on April 20, 2024

@fzaninotto you mean can use props 'asyncValidate' in SimpleForm of 3.0?

from react-admin.

fzaninotto avatar fzaninotto commented on April 20, 2024

I mean you have to look at how react-final-form handles it. I have no idea how it works, we don't need it for now, so you'll have to do the digging.

from react-admin.

anewcoder1992 avatar anewcoder1992 commented on April 20, 2024

@fzaninotto ok i have try ,thanks a lot

from react-admin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.