简体   繁体   English

React/Formik 如何将按钮“提交”从“表单”块移动到页面上的另一个块?或者如何使用另一个按钮从表单中获取所有值?

[英]React/Formik How can I move button 'submit' from 'form' block to another block on page?Or how can I use another button to get all values from my form?

How can I move button 'submit' from 'form' block to another block on page?Or how can I use another button to get all values from my form?如何将按钮“提交”从“表单”块移动到页面上的另一个块?或者如何使用另一个按钮从表单中获取所有值?

<Formik
      initialValues={{
        street: "",
        secondName: "",
        password: "",
        confirmPassword: "",
        email: "",
        confirmEmail: ""
      }}
      validateOnBlur
      onSubmit={(values) => {
        console.log(values);
      }}
      validationSchema={validationsSchema}
    >
      {({
        values,
        errors,
        touched,
        handleChange,
        handleBlur,
        isValid,
        handleSubmit,
        dirty
      }) => (
        <div className={s.formikBody}>
          <p className={s.sizeBig}>
            <label htmlFor={`street`}>Street *</label>
            <br />
            <input
              className={cn(s.input)}
              type={`text`}
              name={`street`}
              onChange={handleChange}
              onBlur={handleBlur}
              value={values.street}
            />
          </p>
          <p className={s.sizeSmall}>
            <label htmlFor={`secondName`}>secondName</label>
            <br />
            <input
              className={s.input}
              type={`text`}
              name={`secondName`}
              onChange={handleChange}
              onBlur={handleBlur}
              value={values.secondName}
            />
          </p>
          <p className={s.sizeSmall}>
            <label htmlFor={`password`}>password</label>
            <br />
            <input
              className={s.input}
              type={`password`}
              name={`password`}
              onChange={handleChange}
              onBlur={handleBlur}
              value={values.password}
            />
          </p>
          <p className={s.sizeSmall}>
            <label htmlFor={`confirmPassword`}>confirmPassword</label>
            <br />
            <input
              className={s.input}
              type={`password`}
              name={`confirmPassword`}
              onChange={handleChange}
              onBlur={handleBlur}
              value={values.confirmPassword}
            />
          </p>
          <p className={s.sizeSmall}>
            <label htmlFor={`email`}>email</label>
            <br />
            <input
              className={s.input}
              type={`email`}
              name={`email`}
              onChange={handleChange}
              onBlur={handleBlur}
              value={values.email}
            />
          </p>
          <p>
            <label htmlFor={`confirmEmail`}>confirmEmail</label>
            <br />
            <input
              className={s.input}
              type={`email`}
              name={`confirmEmail`}
              onChange={handleChange}
              onBlur={handleBlur}
              value={values.confirmEmail}
            />
          </p>
          ```{" "}
          <button
            disabled={!isValid && !dirty}
            onClick={handleSubmit}
            type={`submit`}
          >
            submit
          </button>
          <div>
            {touched.street && errors.street && (
              <p className={s.error}>{errors.street}</p>
            )}
            {touched.secondName && errors.secondName && (
              <p className={s.error}>{errors.secondName}</p>
            )}
            {touched.password && errors.password && (
              <p className={s.error}>{errors.password}</p>
            )}
            {touched.confirmPassword && errors.confirmPassword && (
              <p className={s.error}>{errors.confirmPassword}</p>
            )}
            {touched.email && errors.email && (
              <p className={s.error}>{errors.email}</p>
            )}
            {touched.confirmEmail && errors.confirmEmail && (
              <p className={s.error}>{errors.confirmEmail}</p>
            )}
          </div>
        </div>
      )}
    </Formik>

I made a solution for you as I understood your concern我了解您的担忧,为您制定了解决方案

https://codesandbox.io/s/step-form-stack-overflow-bhe3ib?file=/src/App.js https://codesandbox.io/s/step-form-stack-overflow-bhe3ib?file=/src/App.js

please check请检查

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何在提交表单时将结果重定向到 React 中的另一个页面 - How can I on Submit my Form redirect the Results to another Page in React Formik表单正在提交时,如何向按钮添加类? - How can I add a class to a button when a Formik Form isSubmitting? 使用 React &amp; Formik,如何从外部触发 Formik onSubmit<form> 零件?</form> - Using React & Formik, how can I trigger the Formik onSubmit from outside of the <Form> component? react native:当我从另一个页面单击按钮时,如何更改视图? - react native: How can I change a view when i click a button from another page? 当用户单击提交按钮时,我如何从通过 Reactbootstrap 制作的表单中访问值,我无法获取这些值吗 - How I can access the values from a form made via Reactbootstrap when a user clicks submit button, am I unable to grab the values 如何使用按钮从组件重定向到另一个组件 - how can i get redirected from component to another by using a button 你可以<a>在formik表单中使用标签作为提交按钮吗?</a> - Can you use an <a> tag as the submit button in a formik form? 如何调用另一个页面上的按钮值? - how can I call my button value that is on another page? 在 reactjs 中提交表单后,如何获取数据或将数据从一个页面传递到另一个页面 - How can i get data or pass a data from one page to another after submitting a form in reactjs 如何通过单击按钮从多个选择输入中获取所有值? 反应 - How can I get all the values from multiple select inputs on a button click? React
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM