From 7de4e486e4f4932f1c7957f135accedcb154ea6b Mon Sep 17 00:00:00 2001 From: Kevin Norris Date: Fri, 7 Jul 2017 12:44:53 +1200 Subject: [PATCH] Fix inventory category updating incorrectly Set categoryId to that of previous selection on new foods and when no name has been added. --- .../food/components/inventory/FoodItems.js | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/client/modules/food/components/inventory/FoodItems.js b/client/modules/food/components/inventory/FoodItems.js index fc6a752a..82ac0978 100644 --- a/client/modules/food/components/inventory/FoodItems.js +++ b/client/modules/food/components/inventory/FoodItems.js @@ -136,13 +136,30 @@ class FoodItems extends React.Component { foodName: value => { if (typeof value === 'string') { // The user entered a food name that does not exist yet - this.setState({ modalInputFields: { ...this.state.modalInputFields, name: value, categoryId:"" } }, this.validate) - } else { + this.setState({ + modalInputFields: { + ...this.state.modalInputFields, + name: value, + categoryId: this.state.modalInputFields.categoryId + } + }, this.validate) + } else if (value !== null) { // The user entered an existing food name and autosuggest provided the object for that food - this.setState({ modalInputFields: { ...this.state.modalInputFields, - name: value ? value.name : "", - categoryId: value ? value.categoryId : "" - } }, this.validate) + this.setState({ + modalInputFields: { + ...this.state.modalInputFields, + name: value ? value.name : "", + categoryId: value ? value.categoryId : "" + } + }, this.validate) + } else { + this.setState({ + modalInputFields: { + ...this.state.modalInputFields, + name: "", + categoryId: this.state.modalInputFields.categoryId + } + }, this.validate) } }, foodQuantity: e =>