andyrichardson / fielder

A field-first form library for React and React Native
https://fielder.andyrichardson.dev
MIT License
196 stars 10 forks source link

Add means for awaiting validation in submit function #265

Closed andyrichardson closed 3 years ago

andyrichardson commented 4 years ago

About

When the user submits, it would be useful if they could await any in-progress validation.

In-progress validation only applies to forms using async validation.

const { isValidAsync } = useFormContext();

const handleSubmit = useCallback(async () => {
  const isValid = await isValidAsync;

  if (!isValid) {
    return; // Just return - field will have validation error
  }

  // submission logic...
}, [isValidAsync]);
andyrichardson commented 3 years ago

Fixed in #296