问题描述
我正在尝试将字段键入数字:
<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
中指定的数字值不匹配
有什么方法可以将值捕获为字符串以外的数据类型?
解决方法
从事件中获取值并将其转换为数字。
service php-fpm restart # most centos
service php7-php-fpm restart # centos and remi php7
service php7.0-fpm restart # ubuntu