Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

formik clear field

import { Formik, Field, Form, ErrorMessage } from 'formik';
import * as Yup from 'yup';

const LoginForm = (props) => {
    return (
        <>
            <h1>LoginForm</h1>
            <Formik
                initialValues={{ email: '', password: ''}}
                validationSchema={Yup.object({
                    email: Yup.string()
                        .max(40, 'Must be 40 characters or less')
                        .required('Required'),
                    password: Yup.string()
                        .max(20, 'Must be 20 characters or less')
                        .required('Required'),
                })}
                // resetForm to clear formik fields after submit
                onSubmit={(values, { resetForm }) => {
                    console.log(values)
                    resetForm({values: ''})
                }}>
                <Form>
                    <div>
                        <label htmlFor="email">Email</label>
                        <Field name="email" type="text" />
                        <ErrorMessage name="email" />
                    </div>
                    <div>
                        <label htmlFor="password">Password</label>
                        <Field name="password" type="text" />
                        <ErrorMessage name="password" />
                    </div>
                    <button type="submit">Submit</button>
                </Form>
            </Formik>
        </>

    );
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: express redirect to url 
Javascript :: create textbox using javascript 
Javascript :: get element font size javascript 
Javascript :: javascript multiline string 
Javascript :: convert a string to a number in javascript 
Javascript :: angular cli path environment variable 
Javascript :: how to parse json in java 
Javascript :: infinite loop in programming 
Javascript :: react-select dropdown open inside modal 
Javascript :: js skip to next iteration 
Javascript :: window vue remove event listener 
Javascript :: adding binary numbers in javascript 
Javascript :: convert array to object in javascript 
Javascript :: push only elements list into another list javascript 
Javascript :: ReferenceError 
Javascript :: sequelize.org findById 
Javascript :: uppercase in word javascript 
Javascript :: $(document).ready, window.onload 
Javascript :: find biggest word in the string 
Javascript :: jquery alert design 
Javascript :: Add event listener for loop 
Javascript :: how to delete a variable in js 
Javascript :: how to make div visible and invisible in javascript 
Javascript :: get the integer after decimal in javascript 
Javascript :: react native scaling font 
Javascript :: javascript get child element by class 
Javascript :: pdf table files download react not working 
Javascript :: express get raw path 
Javascript :: javascript string contains multiple substrings 
Javascript :: react native position text in center of view 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =