Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // instalar => npm install --save keycode
- const getFoodUuid = (data, item) => data.find(i => i.label === item).uuid
- // AUTOCOMPLETE
- handleInputChange = event => {
- this.setState({ inputValue: event.target.value })
- }
- // AUTOCOMPLETE
- handleChange = item => {
- let { selectedItem, selectedFood } = this.state
- if (selectedItem.indexOf(item) === -1) {
- selectedItem = [...selectedItem, item]
- selectedFood = [...selectedFood, getFoodUuid(this.state.foodCatalog, item)]
- }
- this.setState({
- inputValue: '',
- selectedItem,
- selectedFood
- })
- }
- // AUTOCOMPLETE
- handleKeyDown = event => {
- const { inputValue, selectedItem } = this.state
- if (selectedItem.length && !inputValue.length && keycode(event) === 'backspace') {
- this.setState({
- selectedItem: selectedItem.slice(0, selectedItem.length - 1),
- })
- }
- }
- // AUTOCOMPLETE
- handleDelete = item => () => {
- this.setState(state => {
- const selectedItem = [...state.selectedItem]
- const selectedFood = [...state.selectedFood]
- selectedItem.splice(selectedItem.indexOf(item), 1)
- selectedFood.splice(selectedFood.indexOf(getFoodUuid(this.state.foodCatalog, item)), 1)
- return {
- selectedItem,
- selectedFood
- }
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement