From 1282ed3dc05522025c6f80adee253b754da314ae Mon Sep 17 00:00:00 2001 From: Thirdoptics <23142677+Thirdoptics@users.noreply.github.com> Date: Mon, 30 Oct 2017 13:32:55 -0700 Subject: [PATCH] Selecting item from autosuggest now moves focus to quantity (#269) --- .../food/components/inventory/FoodItems.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/client/modules/food/components/inventory/FoodItems.js b/client/modules/food/components/inventory/FoodItems.js index f5eb69a8..57bbe474 100644 --- a/client/modules/food/components/inventory/FoodItems.js +++ b/client/modules/food/components/inventory/FoodItems.js @@ -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 */ @@ -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: { @@ -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}} />