描述:
点击按钮给antd-mobile的输入组件InputItem进行赋值,用的方法是this.props.form.setFieldsValue()
,但是赋值不成功,输入框中未出现数值
相关代码
<List>
<InputItem className="customized-input"
{...getFieldProps("money", {
normalize: (v, prev) => {
if (v && !/^(([1-9]\d*)|0)(\.\d{0,2}?)?$/.test(v)) {
if(v === "."){
return "0.";
}
return prev;
}
return v;
},
rules: [
{validator: this.validateAmount}
],
onChange: (v) => this.getTradeShare(v)
})}
type={type}
maxLength={8}
placeholder={placeholder}
ref={el => this.inputRef = el}
onVirtualKeyboardConfirm={v => this.getTradeShare(v)}
clear
moneyKeyboardAlign="left"
moneyKeyboardWrapProps={moneyKeyboardWrapProps}
>
</InputItem>
</List>
按钮绑定事件
setAmount(amount) {
this.props.form.setFields({
'money' : amount
});
}
预期结果
点击按钮赋值成功,输入框中显示数值,触发校验规则
实际结果
赋值不成功,输入框未显示数值,未触发校验规则