Handle change on Autocomplete Component from material ui

前端 未结 5 867
無奈伤痛
無奈伤痛 2021-02-01 17:36

I want to use Autocomplete component for input tags. I\'m trying to get the tags and save them on a state so I can later save them on the database. I\'m using funct

5条回答
  •  深忆病人
    2021-02-01 18:29

    I needed to hit my api on every input change to get my tags from backend!

    Use Material-ui onInputChange if you want to get your suggested tags on every input change!

    this.state = {
      // labels are temp, will change every time on auto complete
      labels: [],
      // these are the ones which will be send with content
      selectedTags: [],
    }
    }
    
    //to get the value on every input change
    onInputChange(event,value){
    console.log(value)
    //response from api
    .then((res) => {
          this.setState({
            labels: res
          })
        })
    
    }
    
    //to select input tags
    onSelectTag(e, value) {
    this.setState({
      selectedTags: value
    })
    }
    
    
                 option.title}
                onChange={this.onSelectTag} // click on the show tags
                onInputChange={this.onInputChange} //** on every input change hitting my api**
                filterSelectedOptions
                renderInput={(params) => (
                  
    

提交回复
热议问题