Skip to content
This repository has been archived by the owner on Jul 17, 2020. It is now read-only.

Selecting item from autosuggest now moves focus to quantity #269

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion client/modules/food/components/inventory/FoodItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ class FoodItems extends React.Component {
this.setState({ validInput: this.getValidationState.all() && this.checkChanged() })
}

/**
* callback for setState when user selects an existing food name from Autosuggest
*/
validateFocus = () => {
this.validate
this.quantity.focus()

//moves cursor to end of field on edit
let storedValue = this.quantity.value
this.quantity.value = ''
this.quantity.value = storedValue
}

/**
* check whether newly edited values are different from the inital values
*/
Expand Down Expand Up @@ -178,7 +191,7 @@ class FoodItems extends React.Component {
name: value ? value.name : "",
categoryId: value ? value.categoryId : ""
},
}, this.validate)
}, this.validateFocus)
} else {
this.setState({
modalInputFields: {
Expand Down Expand Up @@ -314,6 +327,7 @@ class FoodItems extends React.Component {
value={this.state.modalInputFields.quantity}
placeholder="Quantity"
onChange={this.handleChange.foodQuantity}
inputRef={ref => {this.quantity = ref}}
/>
</FormGroup>
<input type="submit" style={{ position: "absolute", left: "-9999px", width: "1px", height: "1px" }} />
Expand Down