Autocomplete

UI Components for React
Post Reply
onur301
Posts: 1
Joined: 10 Oct 2018, 11:01

10 Oct 2018, 11:08

Can i specify value for selected items?
If selected item exist in my itemlist then value must be selected items value.
If entry not exist in suggestionlist, selected value must be "0".
Can i apply this scenario to primereact autocomplete?

merve7
Posts: 861
Joined: 12 Sep 2017, 10:44

19 Oct 2018, 09:55

Yes, you can specify selected value. You can try like the below code; (from showcase advanced example);

Code: Select all

 componentDidMount() {
        this.brands = ['Audi', 'BMW', 'Fiat', 'Ford', 'Honda', 'Jaguar', 'Mercedes', 'Renault', 'Volvo'];

        for(let i = 0; i<this.brands.length; i++){
            if(this.brands[i].localeCompare('BMW') === 0){
                this.setState({brand:'BMW'})
                break;
            }
            else
                this.setState({brand:'0'})
        }
    }

Code: Select all

                    <AutoComplete value={this.state.brand} suggestions={this.state.filteredBrands} completeMethod={this.filterBrands} size={30} minLength={1}
                        placeholder="Hint: type 'v' or 'f'" dropdown={true} itemTemplate={this.itemTemplate.bind(this)} onChange={(e) => this.setState({brand: e.value})} />
                    <span style={{ marginLeft: '50px' }}>Brand: {this.state.brand || 'none'}</span>
                    

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 19 guests