Skip to content

Instantly share code, notes, and snippets.

@cybercris
Last active March 30, 2020 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cybercris/6e2cc9600dc7b65b7fc1ef2824b07a11 to your computer and use it in GitHub Desktop.
Save cybercris/6e2cc9600dc7b65b7fc1ef2824b07a11 to your computer and use it in GitHub Desktop.
html
<form onSubmit={formik.handleSubmit}>
<h5>Handling dynamic validation with formik and yup</h5>
<div
className="text"
style={{ backgroundColor: valid ? "green" : "red" }}
>
Valid Data: {"" + valid}
</div>
<input
type="text"
name="otherData"
value={formik.values.otherData}
onChange={handleChange}
onBlur={formik.handleBlur}
/>
<button type="submit">Submit</button>
<br />
{!valid && formik.touched.otherData && (
<div className="blackText">this field is required</div>
)}
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment