【问题标题】:antd, Set value in input field based on a selected value in the drop down listantd,根据下拉列表中的选定值设置输入字段中的值
【发布时间】:2020-05-20 06:38:43
【问题描述】:

我想要的是,当我从 Templates 下拉列表中选择特定值时,Note 文本框应显示基于 Templates 中所选值的值 下拉。

      <Form.Item label="Templates" name="Templates">
          <Select size="small"
            placeholder="Select..."
            allowClear
            showSearch
            filterOption={(input, option) =>
                option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                }
            onChange ={(e) => 
              {
                const newValue = e;
                const {change} = this.props
              change('Note', _.find( MasterData.NotesTemplates, { TemplateLabel: newValue }).TemplateText)
              this.setState({selectedTemplate: newValue});
            }
            }
          >
            {MasterData && MasterData.NotesTemplates && MasterData.NotesTemplates.map((dd)=><Select.Option value={dd.TemplateLabel}>{dd.TemplateLabel}</Select.Option>)}

            </Select>
      </Form.Item>
<Form.Item label="Note" name="Note" rules={[{required:true,message:'Please Input!'}]}>
              <Input.TextArea autoSize size="small"  />
          </Form.Item>

我在onChange 中使用了change 函数,但出现此错误

TypeError:更改不是函数

我可以使用什么内置函数来代替change

【问题讨论】:

    标签: reactjs forms antd


    【解决方案1】:

    找到答案

    this.form.setFieldsValue({'Note': _.find( MasterData.NotesTemplates, { TemplateLabel: newValue }).TemplateText})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-09
      • 1970-01-01
      • 2019-04-17
      • 1970-01-01
      相关资源
      最近更新 更多