Skip to content
Advertisement

Async form field validation in ant design

How to validate form fields asynchronously in ant design?

JavaScript

function call

JavaScript

How to show the error message from api response? As api call takes some time to complete at that time the validation function call get executed completely before api request complete. So how can i show the error message?

Advertisement

Answer

You’re missing await before validateZipcode and async before handlezipCodeChange:

JavaScript

also, as mentioned in comment, you need to add await to your validateZipcode function:

JavaScript

You need to add it because actually, it’s impossible to catch completeness of async operation in sync function.

Other solution is to unmark async from validateZipcode, and next use it as Promise-based:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement