是否可以将数字存储在表单值中?

问题描述

我正在尝试将字段键入数字:

<Form
      onSubmit={onSubmit}
      initialValues={{ target_type_id: 1 }}
      render={({ handleSubmit,form,submitting,pristine,values }) => (
        <form onSubmit={handleSubmit}>
          <Field<number> name="target_type_id" type="radio" value={1}>
            {({ input }) => (
              <label>
                <input {...input} /> Alert
              </label>
            )}
          </Field>
          <Field<number> name="target_type_id" type="radio" value={2}>
            {({ input }) => (
              <label>
                <input {...input} /> Lookout
              </label>
            )}
          </Field>
          <Field<number> name="target_type_id" type="radio" value={3}>
            {({ input }) => (
              <label>
                <input {...input} /> Target
              </label>
            )}
          </Field>
          <Field<number> name="target_type_id" type="radio" value={4}>
            {({ input }) => (
              <label>
                <input {...input} /> Blitz
              </label>
            )}
          </Field>
          <pre style={{ flexGrow: 1 }}>
            {JSON.stringify(values,undefined,2)}
          </pre>
        </form>
      )}
    />

但是,当我单击单选按钮时,捕获的值是一个字符串,因此它与Field中指定的数字值不匹配

有什么方法可以将值捕获为字符串以外的数据类型?

https://codesandbox.io/s/strongly-typed-form-values-with-react-final-form-forked-cvn4t?file=/src/index.tsx:918-2141

解决方法

从事件中获取值并将其转换为数字。

service php-fpm restart # most centos
service php7-php-fpm restart # centos and remi php7
service php7.0-fpm restart # ubuntu

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...