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?
Autocomplete
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>
-
- Information
-
Who is online
Users browsing this forum: No registered users and 19 guests