Antd Form组件getFieldDecorator设置Input替换空格

核心代码 

   getValueFromEvent: event => event.target.value.replace(/\s+/g, ''),

项目中使用

<FormItem>
                    {getFieldDecorator(item.labelKey, {
                      rules: [{ required: item.required, message: `请输入${item.labelName}` }],
                      getValueFromEvent: event => event.target.value.replace(/\s+/g, ''),
                    })(
                      item.type === 'NUMBER' ? (
                        <InputNumber
                          style={
   
   { width: 180, marginRight: '16px' }}
                          min={1}
                          max={750}
                          placeholder={`请输入${item.labelName}`}
                        />
                      ) : (
                        <Input
                          placeholder={`请输入${item.labelName}`}
                          style={
   
   { width: 180, marginRight: '16px' }}
                        />
                      ),
                    )}
                  </FormItem>

猜你喜欢

转载自blog.csdn.net/weixin_39706415/article/details/100518822