reactjs - 如何格式化 Formik 中 onBlur 事件的输入值?

标签 reactjs formik

使用Formik ,当onBlur事件发生时,如何改变输入的值?

我有一个 Formik 表单,其中包含电话号码输入,我想在输入模糊时格式化电话号码。

最佳答案

这为我解决了这个问题:

<Formik
  render={props => (
    <Form>
      <Field
        name="phone"
        component={CustomInputComponent}
        onBlur={event => {
          const formatted = formatPhoneNumber(props.values['phone']);
          props.setFieldValue('phone', formatted);
          props.handleBlur(event);
        }}
      />
    </Form>
  )}
/>

关于reactjs - 如何格式化 Formik 中 onBlur 事件的输入值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56666244/

相关文章:

javascript - 为什么 onKeyDown 和 onKeyUp 在附加到 contenteditable div 中的跨度时不触发?

reactjs - 错误: Type '{ children: Element[]; }' has no properties in common with type 'IntrinsicAttributes & RefAttributes<HTMLFormElement>'

javascript - formik 警告,组件正在更改要控制的文本类型的不受控制的输入

javascript - 表单提交不适用于validationSchema

reactjs - Formik Yup 验证在触摸字段之前运行

css - 生产 css 中的 Material-ui

reactjs - ' react -i18next : withNamespaces is not a function' when testing

html - react 组件中的 Bootstrap 进度条问题

typescript - 将类型断言与解构赋值结合使用的最佳方式是什么?

javascript - mapStateToProps 中的 ReactJS + Redux Prop 在分派(dispatch)操作时不会刷新