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

Commit

Permalink
Selecting item from autosuggest now moves focus to quantity (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thirdoptics authored and jspaine committed Oct 30, 2017
1 parent 7c35c49 commit 1282ed3
Showing 1 changed file with 15 additions and 1 deletion.
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

0 comments on commit 1282ed3

Please sign in to comment.