javascript - 如何根据选择使新字段出现在表单中

标签 javascript reactjs

如果在标签“Tipo consenso”中我选择选项“Leggi Referto”,我希望显示“Codice Referto”字段,否则我不希望显示它。

      Form onSubmit={this.handleSubmit}>
      <div className="form-section">

        <Label for="type" text="Tipo consenso"  />
        <select
        name="rights"
        value={this.state.rights}
        onChange={this.handleInputChange}>
        <option default value="vuoto"></option>
        <option value="Carica Referto">Carica Referto</option>
        <option value="Leggi Referto">Leggi Referto</option>
        </select>

      <Label text="Codice Referto"  />
        <input
        onVisible={this.checkVisibility}
          type="text"
          name="codiceReferto"
          placeholder="Inserire hash referto"
          autoFocus
          onKeyPress={this.onEnter}     //allows you to move to the next panel with the enter key
          value={this.state.codiceReferto}
          onChange={this.handleInputChange}
        />

最佳答案

尝试下面的代码希望它能帮助你

{
    this.state.rights === 'Leggi Referto' ?
        <div>
            <Label text="Codice Referto" />
            <input
                onVisible={this.checkVisibility}
                type="text"
                name="codiceReferto"
                placeholder="Inserire hash referto"
                autoFocus
                onKeyPress={this.onEnter}     //allows you to move to the next panel with the enter key
                value={this.state.codiceReferto}
                onChange={this.handleInputChange}
            />
        </div> : null
}

关于javascript - 如何根据选择使新字段出现在表单中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57630226/

相关文章:

javascript - 通过 axios 库方法设置状态后,Json 数据未在 ReactJS 类中呈现?

javascript - 在 Javascript 中添加多个变量以使用 RegEx 函数

javascript - 如何在 ReactJS 中处理复杂对象?

javascript - 您将如何修复或改进该组件?

未使用 html 形式的 onsubmit 调用 Javascript 函数

javascript - ( Node :1572) UnhandledPromiseRejectionWarning: ValidationError: profile validation failed: education. 0.fieldsofstudy:需要路径 `fieldsofstudy`

javascript - map 框/传单上的聚类标记

javascript - 对象作为 React 子对象无效(在 android 4.4 的手机中,对于 React 15.6.1)

javascript - 如何使用 reactjs 和 css 创建垂直制表符

javascript - 通过在 typescript 中渲染的字体颜色使用react