Properties of state not setting [“This field is required.”] Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Detecting an undefined object propertyHow to efficiently count the number of keys/properties of an object in JavaScript?How do I check if an object has a property in JavaScript?How can I merge properties of two JavaScript objects dynamically?How do I remove a property from a JavaScript object?Setting “checked” for a checkbox with jQuery?Set a default parameter value for a JavaScript functionSort array of objects by string property valueIterate through object propertiesHow get value datapicker in react toobox custom?
Where and when has Thucydides been studied?
Why did Bronn offer to be Tyrion Lannister's champion in trial by combat?
Russian equivalents of おしゃれは足元から (Every good outfit starts with the shoes)
malloc in main() or malloc in another function: allocating memory for a struct and its members
Does the main washing effect of soap come from foam?
Does the transliteration of 'Dravidian' exist in Hindu scripture? Does 'Dravida' refer to a Geographical area or an ethnic group?
Flight departed from the gate 5 min before scheduled departure time. Refund options
What is the proper term for etching or digging of wall to hide conduit of cables
How do you write "wild blueberries flavored"?
Random body shuffle every night—can we still function?
The Nth Gryphon Number
What is a more techy Technical Writer job title that isn't cutesy or confusing?
Did any compiler fully use 80-bit floating point?
What is "Lambda" in Heston's original paper on stochastic volatility models?
Why can't fire hurt Daenerys but it did to Jon Snow in season 1?
Does a random sequence of vectors span a Hilbert space?
How can I list files in reverse time order by a command and pass them as arguments to another command?
Is it OK to use the testing sample to compare algorithms?
How many time has Arya actually used Needle?
How do I say "this must not happen"?
Why is there so little support for joining EFTA in the British parliament?
Can two people see the same photon?
Is this Half-dragon Quaggoth boss monster balanced?
Why complex landing gears are used instead of simple, reliable and light weight muscle wire or shape memory alloys?
Properties of state not setting [“This field is required.”]
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Detecting an undefined object propertyHow to efficiently count the number of keys/properties of an object in JavaScript?How do I check if an object has a property in JavaScript?How can I merge properties of two JavaScript objects dynamically?How do I remove a property from a JavaScript object?Setting “checked” for a checkbox with jQuery?Set a default parameter value for a JavaScript functionSort array of objects by string property valueIterate through object propertiesHow get value datapicker in react toobox custom?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a django/react (s3 bucket for image upload)project which adds recipes to a postgres database. In my RecipeFormContainer Component one of my properties to the recipe is an Array of ingredients. The array is supposed to be filled with objects that are made up of the key value pairs of units, quantity etc. I have written a method called addIngredients, but it does not seem to be adding the objects into my ingredients array. I get the error "ingredients: ["This field is required."]" when trying to submit my recipe and do a post. Please enlighten me with what I am missing.
Code is as follows:
import React, Component from 'react';
import Form from 'react-bootstrap'
import Button from 'react-bootstrap/Button';
class RecipeFormContainer extends Component
constructor(props)
super(props);
this.state =
title: '',
creator: '',
mealTime: "",
prepTime: "",
cookTime: "",
image_preview: "",
servings: "",
directions: '',
ingredients: [
units: '',
amounts: '',
multiples: '',
quantity: '',
name: ''
],
image: "",
;
this.handleImage = this.handleImage.bind(this);
this.handleIngredientInput = this.handleIngredientInput.bind(this);
this.handleAddIngredients = this.handleAddIngredients.bind(this);
handleAddIngredients =(e) =>
e.preventDefault();
// the ingredients properties are not being added to the ingredients array property on state *************************
let ingredient = units: '',
amounts: '',
multiples: '',
quantity: '',
name: '';
//save the current state of ingredients array in variable ingredient
let ingredients = this.state.ingredients;
// add the ingredient object into the ingredients array ( which is a property of state)
ingredients.push(ingredient);
// set the new array of ingredients as the state of the property ingredients
this.setState( ingredients: ingredients);
;
handleInput = (e) =>
e.preventDefault();
this.setState([e.target.name]: e.target.value);
;
handleIngredientInput = (e) =>
e.preventDefault();
this.setState([e.target.name]: e.target.value)
;
handleImage(event)
event.preventDefault();
// this makes it show up in preview
let file = event.target.files[0];
let fileReader = new FileReader();
fileReader.onloadend = () => this.setState(image_preview:fileReader.result);
fileReader.readAsDataURL(file);
this.setState(image:file);
submitRecipe = (event) =>
event.preventDefault();
let recipe = ...this.state;
console.log('recipe one', this.state);
let formData = new FormData();
formData.append("image", this.state.image);
formData.append('title', this.state.title);
formData.append("ingredients", this.state.ingredients);
formData.append("mealTime", this.state.mealTime);
formData.append("prepTime", this.state.prepTime);
formData.append("cookTime", this.state.cookTime);
formData.append("image_Preview", this.state.image_preview);
formData.append("servings", this.state.servings);
formData.append("directions", this.state.directions);
formData.append("creator", this.state.creator);
// formData.append("units", this.state.ingredients.units);
// formData.append("amount", this.state.ingredients.amount);
// formData.append("multiples", this.state.ingredients.multiples);
// formData.append("quantity", this.state.ingredients.quantity);
// formData.append("name", this.state.ingredients.name);
// add line for each property of state
const conf =
method: "POST",
body: formData,
;
fetch('/api/recipe/', conf).then((response) =>
return response.json();
).then((json) =>
this.props.addRecipe(json);
);
;
render()
return (
<Form onSubmit=this.submitRecipe encType="multipart/form-data" >
<Form.Group onSubmit=event => event.preventDefault(); >
<img src=this.state.image_preview/>
<input className="input" type="file" onChange=this.handleImage name="image" />
</Form.Group>
<Form.Group controlId="exampleForm.ControlInput1">
<Form.Label>Recipe Name</Form.Label>
<Form.Control type="text" placeholder="Enter Recipe Name Here"
name="title"
value=this.state.title
onChange=this.handleInput/>
<Form.Label>Recipe Creator</Form.Label>
<Form.Control type="text" placeholder="Enter Your Name Here"
value=this.state.creator
name="creator"
onChange=this.handleInput/>
</Form.Group>
<Form.Group controlId="exampleForm.ControlSelect1" id="foodType">
<Form.Label>Example select</Form.Label>
<Form.Control as="select">
<option>Breakfast</option>
<option>Lunch</option>
<option>Dinner</option>
<option>Dessert</option>
<option>Vegetarian</option>
</Form.Control>
</Form.Group>
<Form.Control type="text" placeholder="Prep Time" className="midButt"
value=this.state.prepTime
name="prepTime"
onChange=this.handleInput/>
<Form.Control type="text" placeholder="Cook Time" className="midButt"
value=this.state.cookTime
name="cookTime"
onChange=this.handleInput/>
<Form.Group controlId="exampleForm.ControlSelect1" id="foodTemp">
<Form.Control as="select">
<option>Fahrenheit</option>
<option>Celsius</option>
</Form.Control>
</Form.Group>
<Form.Group>
This Recipe Will Make: <Form.Control type="number" placeholder="servings" id="servings" value=this.state.ingredients.servings onChange=this.handleInput name="servings" />
<Form.Control type="text" placeholder="cookies, loaves, etc." id="loaf" value=this.state.ingredients.multiples onChange=this.handleIngredientInput name="multiples"/>
</Form.Group>
this.state.ingredients.map((ingredient, index) =>
return (
<div key=index>
<Form.Control type="number" placeholder="#" id="numberAmount" value=this.state.ingredients.quantity onChange=this.handleIngredientInput name="amount"/>
<Form.Control type="text" placeholder="units" id="units" value=this.state.ingredients.units onChange=this.handleIngredientInput name="units"/>
<Form.Control type="text" placeholder="Ingredient Name" id="name" value=this.state.ingredients.name onChange=this.handleIngredientInput name="name"/>
</div>
);
);
<Button variant="light" onClick = this.handleAddIngredients> + </Button>
/*/!*will update state with event handler this.state.ingredients, append object to array *!/*/
<Form.Group controlId="exampleForm.ControlTextarea1">
<Form.Label>Directions</Form.Label>
<Form.Control as="textarea" rows="3"
value=this.state.directions
name="directions"
onChange=this.handleInput/>
</Form.Group>
<Button type="submit" variant="secondary">Save This Recipe !</Button>
</Form>
)
;
export default RecipeFormContainer;
javascript django reactjs amazon-s3 react-bootstrap
add a comment |
I have a django/react (s3 bucket for image upload)project which adds recipes to a postgres database. In my RecipeFormContainer Component one of my properties to the recipe is an Array of ingredients. The array is supposed to be filled with objects that are made up of the key value pairs of units, quantity etc. I have written a method called addIngredients, but it does not seem to be adding the objects into my ingredients array. I get the error "ingredients: ["This field is required."]" when trying to submit my recipe and do a post. Please enlighten me with what I am missing.
Code is as follows:
import React, Component from 'react';
import Form from 'react-bootstrap'
import Button from 'react-bootstrap/Button';
class RecipeFormContainer extends Component
constructor(props)
super(props);
this.state =
title: '',
creator: '',
mealTime: "",
prepTime: "",
cookTime: "",
image_preview: "",
servings: "",
directions: '',
ingredients: [
units: '',
amounts: '',
multiples: '',
quantity: '',
name: ''
],
image: "",
;
this.handleImage = this.handleImage.bind(this);
this.handleIngredientInput = this.handleIngredientInput.bind(this);
this.handleAddIngredients = this.handleAddIngredients.bind(this);
handleAddIngredients =(e) =>
e.preventDefault();
// the ingredients properties are not being added to the ingredients array property on state *************************
let ingredient = units: '',
amounts: '',
multiples: '',
quantity: '',
name: '';
//save the current state of ingredients array in variable ingredient
let ingredients = this.state.ingredients;
// add the ingredient object into the ingredients array ( which is a property of state)
ingredients.push(ingredient);
// set the new array of ingredients as the state of the property ingredients
this.setState( ingredients: ingredients);
;
handleInput = (e) =>
e.preventDefault();
this.setState([e.target.name]: e.target.value);
;
handleIngredientInput = (e) =>
e.preventDefault();
this.setState([e.target.name]: e.target.value)
;
handleImage(event)
event.preventDefault();
// this makes it show up in preview
let file = event.target.files[0];
let fileReader = new FileReader();
fileReader.onloadend = () => this.setState(image_preview:fileReader.result);
fileReader.readAsDataURL(file);
this.setState(image:file);
submitRecipe = (event) =>
event.preventDefault();
let recipe = ...this.state;
console.log('recipe one', this.state);
let formData = new FormData();
formData.append("image", this.state.image);
formData.append('title', this.state.title);
formData.append("ingredients", this.state.ingredients);
formData.append("mealTime", this.state.mealTime);
formData.append("prepTime", this.state.prepTime);
formData.append("cookTime", this.state.cookTime);
formData.append("image_Preview", this.state.image_preview);
formData.append("servings", this.state.servings);
formData.append("directions", this.state.directions);
formData.append("creator", this.state.creator);
// formData.append("units", this.state.ingredients.units);
// formData.append("amount", this.state.ingredients.amount);
// formData.append("multiples", this.state.ingredients.multiples);
// formData.append("quantity", this.state.ingredients.quantity);
// formData.append("name", this.state.ingredients.name);
// add line for each property of state
const conf =
method: "POST",
body: formData,
;
fetch('/api/recipe/', conf).then((response) =>
return response.json();
).then((json) =>
this.props.addRecipe(json);
);
;
render()
return (
<Form onSubmit=this.submitRecipe encType="multipart/form-data" >
<Form.Group onSubmit=event => event.preventDefault(); >
<img src=this.state.image_preview/>
<input className="input" type="file" onChange=this.handleImage name="image" />
</Form.Group>
<Form.Group controlId="exampleForm.ControlInput1">
<Form.Label>Recipe Name</Form.Label>
<Form.Control type="text" placeholder="Enter Recipe Name Here"
name="title"
value=this.state.title
onChange=this.handleInput/>
<Form.Label>Recipe Creator</Form.Label>
<Form.Control type="text" placeholder="Enter Your Name Here"
value=this.state.creator
name="creator"
onChange=this.handleInput/>
</Form.Group>
<Form.Group controlId="exampleForm.ControlSelect1" id="foodType">
<Form.Label>Example select</Form.Label>
<Form.Control as="select">
<option>Breakfast</option>
<option>Lunch</option>
<option>Dinner</option>
<option>Dessert</option>
<option>Vegetarian</option>
</Form.Control>
</Form.Group>
<Form.Control type="text" placeholder="Prep Time" className="midButt"
value=this.state.prepTime
name="prepTime"
onChange=this.handleInput/>
<Form.Control type="text" placeholder="Cook Time" className="midButt"
value=this.state.cookTime
name="cookTime"
onChange=this.handleInput/>
<Form.Group controlId="exampleForm.ControlSelect1" id="foodTemp">
<Form.Control as="select">
<option>Fahrenheit</option>
<option>Celsius</option>
</Form.Control>
</Form.Group>
<Form.Group>
This Recipe Will Make: <Form.Control type="number" placeholder="servings" id="servings" value=this.state.ingredients.servings onChange=this.handleInput name="servings" />
<Form.Control type="text" placeholder="cookies, loaves, etc." id="loaf" value=this.state.ingredients.multiples onChange=this.handleIngredientInput name="multiples"/>
</Form.Group>
this.state.ingredients.map((ingredient, index) =>
return (
<div key=index>
<Form.Control type="number" placeholder="#" id="numberAmount" value=this.state.ingredients.quantity onChange=this.handleIngredientInput name="amount"/>
<Form.Control type="text" placeholder="units" id="units" value=this.state.ingredients.units onChange=this.handleIngredientInput name="units"/>
<Form.Control type="text" placeholder="Ingredient Name" id="name" value=this.state.ingredients.name onChange=this.handleIngredientInput name="name"/>
</div>
);
);
<Button variant="light" onClick = this.handleAddIngredients> + </Button>
/*/!*will update state with event handler this.state.ingredients, append object to array *!/*/
<Form.Group controlId="exampleForm.ControlTextarea1">
<Form.Label>Directions</Form.Label>
<Form.Control as="textarea" rows="3"
value=this.state.directions
name="directions"
onChange=this.handleInput/>
</Form.Group>
<Button type="submit" variant="secondary">Save This Recipe !</Button>
</Form>
)
;
export default RecipeFormContainer;
javascript django reactjs amazon-s3 react-bootstrap
try to console.log yourthis.state.ingredients
and look what's there when you add a new ingredient. Maybe the result isn't what you was expecting
– mthrsj
Mar 9 at 1:39
It is empty. My handleIngredientInput method is not doing what I expected. I am unsure of the syntax to make the logic I want work correctly. DO you have any advice ?
– Christina Roberts
Mar 9 at 11:35
add a comment |
I have a django/react (s3 bucket for image upload)project which adds recipes to a postgres database. In my RecipeFormContainer Component one of my properties to the recipe is an Array of ingredients. The array is supposed to be filled with objects that are made up of the key value pairs of units, quantity etc. I have written a method called addIngredients, but it does not seem to be adding the objects into my ingredients array. I get the error "ingredients: ["This field is required."]" when trying to submit my recipe and do a post. Please enlighten me with what I am missing.
Code is as follows:
import React, Component from 'react';
import Form from 'react-bootstrap'
import Button from 'react-bootstrap/Button';
class RecipeFormContainer extends Component
constructor(props)
super(props);
this.state =
title: '',
creator: '',
mealTime: "",
prepTime: "",
cookTime: "",
image_preview: "",
servings: "",
directions: '',
ingredients: [
units: '',
amounts: '',
multiples: '',
quantity: '',
name: ''
],
image: "",
;
this.handleImage = this.handleImage.bind(this);
this.handleIngredientInput = this.handleIngredientInput.bind(this);
this.handleAddIngredients = this.handleAddIngredients.bind(this);
handleAddIngredients =(e) =>
e.preventDefault();
// the ingredients properties are not being added to the ingredients array property on state *************************
let ingredient = units: '',
amounts: '',
multiples: '',
quantity: '',
name: '';
//save the current state of ingredients array in variable ingredient
let ingredients = this.state.ingredients;
// add the ingredient object into the ingredients array ( which is a property of state)
ingredients.push(ingredient);
// set the new array of ingredients as the state of the property ingredients
this.setState( ingredients: ingredients);
;
handleInput = (e) =>
e.preventDefault();
this.setState([e.target.name]: e.target.value);
;
handleIngredientInput = (e) =>
e.preventDefault();
this.setState([e.target.name]: e.target.value)
;
handleImage(event)
event.preventDefault();
// this makes it show up in preview
let file = event.target.files[0];
let fileReader = new FileReader();
fileReader.onloadend = () => this.setState(image_preview:fileReader.result);
fileReader.readAsDataURL(file);
this.setState(image:file);
submitRecipe = (event) =>
event.preventDefault();
let recipe = ...this.state;
console.log('recipe one', this.state);
let formData = new FormData();
formData.append("image", this.state.image);
formData.append('title', this.state.title);
formData.append("ingredients", this.state.ingredients);
formData.append("mealTime", this.state.mealTime);
formData.append("prepTime", this.state.prepTime);
formData.append("cookTime", this.state.cookTime);
formData.append("image_Preview", this.state.image_preview);
formData.append("servings", this.state.servings);
formData.append("directions", this.state.directions);
formData.append("creator", this.state.creator);
// formData.append("units", this.state.ingredients.units);
// formData.append("amount", this.state.ingredients.amount);
// formData.append("multiples", this.state.ingredients.multiples);
// formData.append("quantity", this.state.ingredients.quantity);
// formData.append("name", this.state.ingredients.name);
// add line for each property of state
const conf =
method: "POST",
body: formData,
;
fetch('/api/recipe/', conf).then((response) =>
return response.json();
).then((json) =>
this.props.addRecipe(json);
);
;
render()
return (
<Form onSubmit=this.submitRecipe encType="multipart/form-data" >
<Form.Group onSubmit=event => event.preventDefault(); >
<img src=this.state.image_preview/>
<input className="input" type="file" onChange=this.handleImage name="image" />
</Form.Group>
<Form.Group controlId="exampleForm.ControlInput1">
<Form.Label>Recipe Name</Form.Label>
<Form.Control type="text" placeholder="Enter Recipe Name Here"
name="title"
value=this.state.title
onChange=this.handleInput/>
<Form.Label>Recipe Creator</Form.Label>
<Form.Control type="text" placeholder="Enter Your Name Here"
value=this.state.creator
name="creator"
onChange=this.handleInput/>
</Form.Group>
<Form.Group controlId="exampleForm.ControlSelect1" id="foodType">
<Form.Label>Example select</Form.Label>
<Form.Control as="select">
<option>Breakfast</option>
<option>Lunch</option>
<option>Dinner</option>
<option>Dessert</option>
<option>Vegetarian</option>
</Form.Control>
</Form.Group>
<Form.Control type="text" placeholder="Prep Time" className="midButt"
value=this.state.prepTime
name="prepTime"
onChange=this.handleInput/>
<Form.Control type="text" placeholder="Cook Time" className="midButt"
value=this.state.cookTime
name="cookTime"
onChange=this.handleInput/>
<Form.Group controlId="exampleForm.ControlSelect1" id="foodTemp">
<Form.Control as="select">
<option>Fahrenheit</option>
<option>Celsius</option>
</Form.Control>
</Form.Group>
<Form.Group>
This Recipe Will Make: <Form.Control type="number" placeholder="servings" id="servings" value=this.state.ingredients.servings onChange=this.handleInput name="servings" />
<Form.Control type="text" placeholder="cookies, loaves, etc." id="loaf" value=this.state.ingredients.multiples onChange=this.handleIngredientInput name="multiples"/>
</Form.Group>
this.state.ingredients.map((ingredient, index) =>
return (
<div key=index>
<Form.Control type="number" placeholder="#" id="numberAmount" value=this.state.ingredients.quantity onChange=this.handleIngredientInput name="amount"/>
<Form.Control type="text" placeholder="units" id="units" value=this.state.ingredients.units onChange=this.handleIngredientInput name="units"/>
<Form.Control type="text" placeholder="Ingredient Name" id="name" value=this.state.ingredients.name onChange=this.handleIngredientInput name="name"/>
</div>
);
);
<Button variant="light" onClick = this.handleAddIngredients> + </Button>
/*/!*will update state with event handler this.state.ingredients, append object to array *!/*/
<Form.Group controlId="exampleForm.ControlTextarea1">
<Form.Label>Directions</Form.Label>
<Form.Control as="textarea" rows="3"
value=this.state.directions
name="directions"
onChange=this.handleInput/>
</Form.Group>
<Button type="submit" variant="secondary">Save This Recipe !</Button>
</Form>
)
;
export default RecipeFormContainer;
javascript django reactjs amazon-s3 react-bootstrap
I have a django/react (s3 bucket for image upload)project which adds recipes to a postgres database. In my RecipeFormContainer Component one of my properties to the recipe is an Array of ingredients. The array is supposed to be filled with objects that are made up of the key value pairs of units, quantity etc. I have written a method called addIngredients, but it does not seem to be adding the objects into my ingredients array. I get the error "ingredients: ["This field is required."]" when trying to submit my recipe and do a post. Please enlighten me with what I am missing.
Code is as follows:
import React, Component from 'react';
import Form from 'react-bootstrap'
import Button from 'react-bootstrap/Button';
class RecipeFormContainer extends Component
constructor(props)
super(props);
this.state =
title: '',
creator: '',
mealTime: "",
prepTime: "",
cookTime: "",
image_preview: "",
servings: "",
directions: '',
ingredients: [
units: '',
amounts: '',
multiples: '',
quantity: '',
name: ''
],
image: "",
;
this.handleImage = this.handleImage.bind(this);
this.handleIngredientInput = this.handleIngredientInput.bind(this);
this.handleAddIngredients = this.handleAddIngredients.bind(this);
handleAddIngredients =(e) =>
e.preventDefault();
// the ingredients properties are not being added to the ingredients array property on state *************************
let ingredient = units: '',
amounts: '',
multiples: '',
quantity: '',
name: '';
//save the current state of ingredients array in variable ingredient
let ingredients = this.state.ingredients;
// add the ingredient object into the ingredients array ( which is a property of state)
ingredients.push(ingredient);
// set the new array of ingredients as the state of the property ingredients
this.setState( ingredients: ingredients);
;
handleInput = (e) =>
e.preventDefault();
this.setState([e.target.name]: e.target.value);
;
handleIngredientInput = (e) =>
e.preventDefault();
this.setState([e.target.name]: e.target.value)
;
handleImage(event)
event.preventDefault();
// this makes it show up in preview
let file = event.target.files[0];
let fileReader = new FileReader();
fileReader.onloadend = () => this.setState(image_preview:fileReader.result);
fileReader.readAsDataURL(file);
this.setState(image:file);
submitRecipe = (event) =>
event.preventDefault();
let recipe = ...this.state;
console.log('recipe one', this.state);
let formData = new FormData();
formData.append("image", this.state.image);
formData.append('title', this.state.title);
formData.append("ingredients", this.state.ingredients);
formData.append("mealTime", this.state.mealTime);
formData.append("prepTime", this.state.prepTime);
formData.append("cookTime", this.state.cookTime);
formData.append("image_Preview", this.state.image_preview);
formData.append("servings", this.state.servings);
formData.append("directions", this.state.directions);
formData.append("creator", this.state.creator);
// formData.append("units", this.state.ingredients.units);
// formData.append("amount", this.state.ingredients.amount);
// formData.append("multiples", this.state.ingredients.multiples);
// formData.append("quantity", this.state.ingredients.quantity);
// formData.append("name", this.state.ingredients.name);
// add line for each property of state
const conf =
method: "POST",
body: formData,
;
fetch('/api/recipe/', conf).then((response) =>
return response.json();
).then((json) =>
this.props.addRecipe(json);
);
;
render()
return (
<Form onSubmit=this.submitRecipe encType="multipart/form-data" >
<Form.Group onSubmit=event => event.preventDefault(); >
<img src=this.state.image_preview/>
<input className="input" type="file" onChange=this.handleImage name="image" />
</Form.Group>
<Form.Group controlId="exampleForm.ControlInput1">
<Form.Label>Recipe Name</Form.Label>
<Form.Control type="text" placeholder="Enter Recipe Name Here"
name="title"
value=this.state.title
onChange=this.handleInput/>
<Form.Label>Recipe Creator</Form.Label>
<Form.Control type="text" placeholder="Enter Your Name Here"
value=this.state.creator
name="creator"
onChange=this.handleInput/>
</Form.Group>
<Form.Group controlId="exampleForm.ControlSelect1" id="foodType">
<Form.Label>Example select</Form.Label>
<Form.Control as="select">
<option>Breakfast</option>
<option>Lunch</option>
<option>Dinner</option>
<option>Dessert</option>
<option>Vegetarian</option>
</Form.Control>
</Form.Group>
<Form.Control type="text" placeholder="Prep Time" className="midButt"
value=this.state.prepTime
name="prepTime"
onChange=this.handleInput/>
<Form.Control type="text" placeholder="Cook Time" className="midButt"
value=this.state.cookTime
name="cookTime"
onChange=this.handleInput/>
<Form.Group controlId="exampleForm.ControlSelect1" id="foodTemp">
<Form.Control as="select">
<option>Fahrenheit</option>
<option>Celsius</option>
</Form.Control>
</Form.Group>
<Form.Group>
This Recipe Will Make: <Form.Control type="number" placeholder="servings" id="servings" value=this.state.ingredients.servings onChange=this.handleInput name="servings" />
<Form.Control type="text" placeholder="cookies, loaves, etc." id="loaf" value=this.state.ingredients.multiples onChange=this.handleIngredientInput name="multiples"/>
</Form.Group>
this.state.ingredients.map((ingredient, index) =>
return (
<div key=index>
<Form.Control type="number" placeholder="#" id="numberAmount" value=this.state.ingredients.quantity onChange=this.handleIngredientInput name="amount"/>
<Form.Control type="text" placeholder="units" id="units" value=this.state.ingredients.units onChange=this.handleIngredientInput name="units"/>
<Form.Control type="text" placeholder="Ingredient Name" id="name" value=this.state.ingredients.name onChange=this.handleIngredientInput name="name"/>
</div>
);
);
<Button variant="light" onClick = this.handleAddIngredients> + </Button>
/*/!*will update state with event handler this.state.ingredients, append object to array *!/*/
<Form.Group controlId="exampleForm.ControlTextarea1">
<Form.Label>Directions</Form.Label>
<Form.Control as="textarea" rows="3"
value=this.state.directions
name="directions"
onChange=this.handleInput/>
</Form.Group>
<Button type="submit" variant="secondary">Save This Recipe !</Button>
</Form>
)
;
export default RecipeFormContainer;
import React, Component from 'react';
import Form from 'react-bootstrap'
import Button from 'react-bootstrap/Button';
class RecipeFormContainer extends Component
constructor(props)
super(props);
this.state =
title: '',
creator: '',
mealTime: "",
prepTime: "",
cookTime: "",
image_preview: "",
servings: "",
directions: '',
ingredients: [
units: '',
amounts: '',
multiples: '',
quantity: '',
name: ''
],
image: "",
;
this.handleImage = this.handleImage.bind(this);
this.handleIngredientInput = this.handleIngredientInput.bind(this);
this.handleAddIngredients = this.handleAddIngredients.bind(this);
handleAddIngredients =(e) =>
e.preventDefault();
// the ingredients properties are not being added to the ingredients array property on state *************************
let ingredient = units: '',
amounts: '',
multiples: '',
quantity: '',
name: '';
//save the current state of ingredients array in variable ingredient
let ingredients = this.state.ingredients;
// add the ingredient object into the ingredients array ( which is a property of state)
ingredients.push(ingredient);
// set the new array of ingredients as the state of the property ingredients
this.setState( ingredients: ingredients);
;
handleInput = (e) =>
e.preventDefault();
this.setState([e.target.name]: e.target.value);
;
handleIngredientInput = (e) =>
e.preventDefault();
this.setState([e.target.name]: e.target.value)
;
handleImage(event)
event.preventDefault();
// this makes it show up in preview
let file = event.target.files[0];
let fileReader = new FileReader();
fileReader.onloadend = () => this.setState(image_preview:fileReader.result);
fileReader.readAsDataURL(file);
this.setState(image:file);
submitRecipe = (event) =>
event.preventDefault();
let recipe = ...this.state;
console.log('recipe one', this.state);
let formData = new FormData();
formData.append("image", this.state.image);
formData.append('title', this.state.title);
formData.append("ingredients", this.state.ingredients);
formData.append("mealTime", this.state.mealTime);
formData.append("prepTime", this.state.prepTime);
formData.append("cookTime", this.state.cookTime);
formData.append("image_Preview", this.state.image_preview);
formData.append("servings", this.state.servings);
formData.append("directions", this.state.directions);
formData.append("creator", this.state.creator);
// formData.append("units", this.state.ingredients.units);
// formData.append("amount", this.state.ingredients.amount);
// formData.append("multiples", this.state.ingredients.multiples);
// formData.append("quantity", this.state.ingredients.quantity);
// formData.append("name", this.state.ingredients.name);
// add line for each property of state
const conf =
method: "POST",
body: formData,
;
fetch('/api/recipe/', conf).then((response) =>
return response.json();
).then((json) =>
this.props.addRecipe(json);
);
;
render()
return (
<Form onSubmit=this.submitRecipe encType="multipart/form-data" >
<Form.Group onSubmit=event => event.preventDefault(); >
<img src=this.state.image_preview/>
<input className="input" type="file" onChange=this.handleImage name="image" />
</Form.Group>
<Form.Group controlId="exampleForm.ControlInput1">
<Form.Label>Recipe Name</Form.Label>
<Form.Control type="text" placeholder="Enter Recipe Name Here"
name="title"
value=this.state.title
onChange=this.handleInput/>
<Form.Label>Recipe Creator</Form.Label>
<Form.Control type="text" placeholder="Enter Your Name Here"
value=this.state.creator
name="creator"
onChange=this.handleInput/>
</Form.Group>
<Form.Group controlId="exampleForm.ControlSelect1" id="foodType">
<Form.Label>Example select</Form.Label>
<Form.Control as="select">
<option>Breakfast</option>
<option>Lunch</option>
<option>Dinner</option>
<option>Dessert</option>
<option>Vegetarian</option>
</Form.Control>
</Form.Group>
<Form.Control type="text" placeholder="Prep Time" className="midButt"
value=this.state.prepTime
name="prepTime"
onChange=this.handleInput/>
<Form.Control type="text" placeholder="Cook Time" className="midButt"
value=this.state.cookTime
name="cookTime"
onChange=this.handleInput/>
<Form.Group controlId="exampleForm.ControlSelect1" id="foodTemp">
<Form.Control as="select">
<option>Fahrenheit</option>
<option>Celsius</option>
</Form.Control>
</Form.Group>
<Form.Group>
This Recipe Will Make: <Form.Control type="number" placeholder="servings" id="servings" value=this.state.ingredients.servings onChange=this.handleInput name="servings" />
<Form.Control type="text" placeholder="cookies, loaves, etc." id="loaf" value=this.state.ingredients.multiples onChange=this.handleIngredientInput name="multiples"/>
</Form.Group>
this.state.ingredients.map((ingredient, index) =>
return (
<div key=index>
<Form.Control type="number" placeholder="#" id="numberAmount" value=this.state.ingredients.quantity onChange=this.handleIngredientInput name="amount"/>
<Form.Control type="text" placeholder="units" id="units" value=this.state.ingredients.units onChange=this.handleIngredientInput name="units"/>
<Form.Control type="text" placeholder="Ingredient Name" id="name" value=this.state.ingredients.name onChange=this.handleIngredientInput name="name"/>
</div>
);
);
<Button variant="light" onClick = this.handleAddIngredients> + </Button>
/*/!*will update state with event handler this.state.ingredients, append object to array *!/*/
<Form.Group controlId="exampleForm.ControlTextarea1">
<Form.Label>Directions</Form.Label>
<Form.Control as="textarea" rows="3"
value=this.state.directions
name="directions"
onChange=this.handleInput/>
</Form.Group>
<Button type="submit" variant="secondary">Save This Recipe !</Button>
</Form>
)
;
export default RecipeFormContainer;
import React, Component from 'react';
import Form from 'react-bootstrap'
import Button from 'react-bootstrap/Button';
class RecipeFormContainer extends Component
constructor(props)
super(props);
this.state =
title: '',
creator: '',
mealTime: "",
prepTime: "",
cookTime: "",
image_preview: "",
servings: "",
directions: '',
ingredients: [
units: '',
amounts: '',
multiples: '',
quantity: '',
name: ''
],
image: "",
;
this.handleImage = this.handleImage.bind(this);
this.handleIngredientInput = this.handleIngredientInput.bind(this);
this.handleAddIngredients = this.handleAddIngredients.bind(this);
handleAddIngredients =(e) =>
e.preventDefault();
// the ingredients properties are not being added to the ingredients array property on state *************************
let ingredient = units: '',
amounts: '',
multiples: '',
quantity: '',
name: '';
//save the current state of ingredients array in variable ingredient
let ingredients = this.state.ingredients;
// add the ingredient object into the ingredients array ( which is a property of state)
ingredients.push(ingredient);
// set the new array of ingredients as the state of the property ingredients
this.setState( ingredients: ingredients);
;
handleInput = (e) =>
e.preventDefault();
this.setState([e.target.name]: e.target.value);
;
handleIngredientInput = (e) =>
e.preventDefault();
this.setState([e.target.name]: e.target.value)
;
handleImage(event)
event.preventDefault();
// this makes it show up in preview
let file = event.target.files[0];
let fileReader = new FileReader();
fileReader.onloadend = () => this.setState(image_preview:fileReader.result);
fileReader.readAsDataURL(file);
this.setState(image:file);
submitRecipe = (event) =>
event.preventDefault();
let recipe = ...this.state;
console.log('recipe one', this.state);
let formData = new FormData();
formData.append("image", this.state.image);
formData.append('title', this.state.title);
formData.append("ingredients", this.state.ingredients);
formData.append("mealTime", this.state.mealTime);
formData.append("prepTime", this.state.prepTime);
formData.append("cookTime", this.state.cookTime);
formData.append("image_Preview", this.state.image_preview);
formData.append("servings", this.state.servings);
formData.append("directions", this.state.directions);
formData.append("creator", this.state.creator);
// formData.append("units", this.state.ingredients.units);
// formData.append("amount", this.state.ingredients.amount);
// formData.append("multiples", this.state.ingredients.multiples);
// formData.append("quantity", this.state.ingredients.quantity);
// formData.append("name", this.state.ingredients.name);
// add line for each property of state
const conf =
method: "POST",
body: formData,
;
fetch('/api/recipe/', conf).then((response) =>
return response.json();
).then((json) =>
this.props.addRecipe(json);
);
;
render()
return (
<Form onSubmit=this.submitRecipe encType="multipart/form-data" >
<Form.Group onSubmit=event => event.preventDefault(); >
<img src=this.state.image_preview/>
<input className="input" type="file" onChange=this.handleImage name="image" />
</Form.Group>
<Form.Group controlId="exampleForm.ControlInput1">
<Form.Label>Recipe Name</Form.Label>
<Form.Control type="text" placeholder="Enter Recipe Name Here"
name="title"
value=this.state.title
onChange=this.handleInput/>
<Form.Label>Recipe Creator</Form.Label>
<Form.Control type="text" placeholder="Enter Your Name Here"
value=this.state.creator
name="creator"
onChange=this.handleInput/>
</Form.Group>
<Form.Group controlId="exampleForm.ControlSelect1" id="foodType">
<Form.Label>Example select</Form.Label>
<Form.Control as="select">
<option>Breakfast</option>
<option>Lunch</option>
<option>Dinner</option>
<option>Dessert</option>
<option>Vegetarian</option>
</Form.Control>
</Form.Group>
<Form.Control type="text" placeholder="Prep Time" className="midButt"
value=this.state.prepTime
name="prepTime"
onChange=this.handleInput/>
<Form.Control type="text" placeholder="Cook Time" className="midButt"
value=this.state.cookTime
name="cookTime"
onChange=this.handleInput/>
<Form.Group controlId="exampleForm.ControlSelect1" id="foodTemp">
<Form.Control as="select">
<option>Fahrenheit</option>
<option>Celsius</option>
</Form.Control>
</Form.Group>
<Form.Group>
This Recipe Will Make: <Form.Control type="number" placeholder="servings" id="servings" value=this.state.ingredients.servings onChange=this.handleInput name="servings" />
<Form.Control type="text" placeholder="cookies, loaves, etc." id="loaf" value=this.state.ingredients.multiples onChange=this.handleIngredientInput name="multiples"/>
</Form.Group>
this.state.ingredients.map((ingredient, index) =>
return (
<div key=index>
<Form.Control type="number" placeholder="#" id="numberAmount" value=this.state.ingredients.quantity onChange=this.handleIngredientInput name="amount"/>
<Form.Control type="text" placeholder="units" id="units" value=this.state.ingredients.units onChange=this.handleIngredientInput name="units"/>
<Form.Control type="text" placeholder="Ingredient Name" id="name" value=this.state.ingredients.name onChange=this.handleIngredientInput name="name"/>
</div>
);
);
<Button variant="light" onClick = this.handleAddIngredients> + </Button>
/*/!*will update state with event handler this.state.ingredients, append object to array *!/*/
<Form.Group controlId="exampleForm.ControlTextarea1">
<Form.Label>Directions</Form.Label>
<Form.Control as="textarea" rows="3"
value=this.state.directions
name="directions"
onChange=this.handleInput/>
</Form.Group>
<Button type="submit" variant="secondary">Save This Recipe !</Button>
</Form>
)
;
export default RecipeFormContainer;
javascript django reactjs amazon-s3 react-bootstrap
javascript django reactjs amazon-s3 react-bootstrap
asked Mar 9 at 0:46
Christina RobertsChristina Roberts
1
1
try to console.log yourthis.state.ingredients
and look what's there when you add a new ingredient. Maybe the result isn't what you was expecting
– mthrsj
Mar 9 at 1:39
It is empty. My handleIngredientInput method is not doing what I expected. I am unsure of the syntax to make the logic I want work correctly. DO you have any advice ?
– Christina Roberts
Mar 9 at 11:35
add a comment |
try to console.log yourthis.state.ingredients
and look what's there when you add a new ingredient. Maybe the result isn't what you was expecting
– mthrsj
Mar 9 at 1:39
It is empty. My handleIngredientInput method is not doing what I expected. I am unsure of the syntax to make the logic I want work correctly. DO you have any advice ?
– Christina Roberts
Mar 9 at 11:35
try to console.log your
this.state.ingredients
and look what's there when you add a new ingredient. Maybe the result isn't what you was expecting– mthrsj
Mar 9 at 1:39
try to console.log your
this.state.ingredients
and look what's there when you add a new ingredient. Maybe the result isn't what you was expecting– mthrsj
Mar 9 at 1:39
It is empty. My handleIngredientInput method is not doing what I expected. I am unsure of the syntax to make the logic I want work correctly. DO you have any advice ?
– Christina Roberts
Mar 9 at 11:35
It is empty. My handleIngredientInput method is not doing what I expected. I am unsure of the syntax to make the logic I want work correctly. DO you have any advice ?
– Christina Roberts
Mar 9 at 11:35
add a comment |
1 Answer
1
active
oldest
votes
Taking a look at your code, your handleAddIngredients
isn't right. You commited two mistakes:
Not collecting data from the inputs
You're not collecting the data from the state to put inside the ingredient
. Your code creates a blank ingredient
to put on the array.
Trying to copy the ingredients
array on the wrong way.
Your code "extracts" the ingredients
from the this.state.ingredients
, but it's not possible. Your ingredients
belongs to your state
, not to state.ingredients
.
Instead of doing
let ingredients = this.state.ingredients
You could do
let ingredients = this.state
Or even
let ingredients = [ ...this.state.ingredients ]
Conclusion
After all the fixes, your code should look like below:
handleAddIngredients = (e) =>
e.preventDefault();
//Extracting the values from the state
let units, amounts, multiples, quantity, name = this.state
// Inserting the values into the new ingredient
let ingredient = units, amounts, multiples, quantity, name
// Creating the copy
let ingredients = [ ... this.state.ingredients ]
// add the ingredient object into the ingredients array ( which is a property of state)
ingredients.push(ingredient);
// set the new array of ingredients in the state
this.setState(ingredients);
;
Thank you so much for taking the time to explain that !I knew my methods were not working correctly, but was not sure how to fix them. I will try this right away !
– Christina Roberts
Mar 9 at 17:49
@ChristinaRoberts, you're welcome! I recommend to you to check if all the other handles are working as expected, also.
– mthrsj
Mar 9 at 17:54
that fixed my problem of being able to add the ingredients, but now further down, the post request is still not working. I am VERY new to the javascript and react side of things so its still a challenge to turn my logic (backend style) into valid javascript code haha
– Christina Roberts
Mar 9 at 18:16
@ChristinaRoberts, as this answer solves your problem of ingredients field being empty, feel free to mark it as solution. If is there any other problem, not related with the first one, I recommend you to ask a new question
– mthrsj
Mar 10 at 11:54
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55072890%2fproperties-of-state-not-setting-this-field-is-required%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Taking a look at your code, your handleAddIngredients
isn't right. You commited two mistakes:
Not collecting data from the inputs
You're not collecting the data from the state to put inside the ingredient
. Your code creates a blank ingredient
to put on the array.
Trying to copy the ingredients
array on the wrong way.
Your code "extracts" the ingredients
from the this.state.ingredients
, but it's not possible. Your ingredients
belongs to your state
, not to state.ingredients
.
Instead of doing
let ingredients = this.state.ingredients
You could do
let ingredients = this.state
Or even
let ingredients = [ ...this.state.ingredients ]
Conclusion
After all the fixes, your code should look like below:
handleAddIngredients = (e) =>
e.preventDefault();
//Extracting the values from the state
let units, amounts, multiples, quantity, name = this.state
// Inserting the values into the new ingredient
let ingredient = units, amounts, multiples, quantity, name
// Creating the copy
let ingredients = [ ... this.state.ingredients ]
// add the ingredient object into the ingredients array ( which is a property of state)
ingredients.push(ingredient);
// set the new array of ingredients in the state
this.setState(ingredients);
;
Thank you so much for taking the time to explain that !I knew my methods were not working correctly, but was not sure how to fix them. I will try this right away !
– Christina Roberts
Mar 9 at 17:49
@ChristinaRoberts, you're welcome! I recommend to you to check if all the other handles are working as expected, also.
– mthrsj
Mar 9 at 17:54
that fixed my problem of being able to add the ingredients, but now further down, the post request is still not working. I am VERY new to the javascript and react side of things so its still a challenge to turn my logic (backend style) into valid javascript code haha
– Christina Roberts
Mar 9 at 18:16
@ChristinaRoberts, as this answer solves your problem of ingredients field being empty, feel free to mark it as solution. If is there any other problem, not related with the first one, I recommend you to ask a new question
– mthrsj
Mar 10 at 11:54
add a comment |
Taking a look at your code, your handleAddIngredients
isn't right. You commited two mistakes:
Not collecting data from the inputs
You're not collecting the data from the state to put inside the ingredient
. Your code creates a blank ingredient
to put on the array.
Trying to copy the ingredients
array on the wrong way.
Your code "extracts" the ingredients
from the this.state.ingredients
, but it's not possible. Your ingredients
belongs to your state
, not to state.ingredients
.
Instead of doing
let ingredients = this.state.ingredients
You could do
let ingredients = this.state
Or even
let ingredients = [ ...this.state.ingredients ]
Conclusion
After all the fixes, your code should look like below:
handleAddIngredients = (e) =>
e.preventDefault();
//Extracting the values from the state
let units, amounts, multiples, quantity, name = this.state
// Inserting the values into the new ingredient
let ingredient = units, amounts, multiples, quantity, name
// Creating the copy
let ingredients = [ ... this.state.ingredients ]
// add the ingredient object into the ingredients array ( which is a property of state)
ingredients.push(ingredient);
// set the new array of ingredients in the state
this.setState(ingredients);
;
Thank you so much for taking the time to explain that !I knew my methods were not working correctly, but was not sure how to fix them. I will try this right away !
– Christina Roberts
Mar 9 at 17:49
@ChristinaRoberts, you're welcome! I recommend to you to check if all the other handles are working as expected, also.
– mthrsj
Mar 9 at 17:54
that fixed my problem of being able to add the ingredients, but now further down, the post request is still not working. I am VERY new to the javascript and react side of things so its still a challenge to turn my logic (backend style) into valid javascript code haha
– Christina Roberts
Mar 9 at 18:16
@ChristinaRoberts, as this answer solves your problem of ingredients field being empty, feel free to mark it as solution. If is there any other problem, not related with the first one, I recommend you to ask a new question
– mthrsj
Mar 10 at 11:54
add a comment |
Taking a look at your code, your handleAddIngredients
isn't right. You commited two mistakes:
Not collecting data from the inputs
You're not collecting the data from the state to put inside the ingredient
. Your code creates a blank ingredient
to put on the array.
Trying to copy the ingredients
array on the wrong way.
Your code "extracts" the ingredients
from the this.state.ingredients
, but it's not possible. Your ingredients
belongs to your state
, not to state.ingredients
.
Instead of doing
let ingredients = this.state.ingredients
You could do
let ingredients = this.state
Or even
let ingredients = [ ...this.state.ingredients ]
Conclusion
After all the fixes, your code should look like below:
handleAddIngredients = (e) =>
e.preventDefault();
//Extracting the values from the state
let units, amounts, multiples, quantity, name = this.state
// Inserting the values into the new ingredient
let ingredient = units, amounts, multiples, quantity, name
// Creating the copy
let ingredients = [ ... this.state.ingredients ]
// add the ingredient object into the ingredients array ( which is a property of state)
ingredients.push(ingredient);
// set the new array of ingredients in the state
this.setState(ingredients);
;
Taking a look at your code, your handleAddIngredients
isn't right. You commited two mistakes:
Not collecting data from the inputs
You're not collecting the data from the state to put inside the ingredient
. Your code creates a blank ingredient
to put on the array.
Trying to copy the ingredients
array on the wrong way.
Your code "extracts" the ingredients
from the this.state.ingredients
, but it's not possible. Your ingredients
belongs to your state
, not to state.ingredients
.
Instead of doing
let ingredients = this.state.ingredients
You could do
let ingredients = this.state
Or even
let ingredients = [ ...this.state.ingredients ]
Conclusion
After all the fixes, your code should look like below:
handleAddIngredients = (e) =>
e.preventDefault();
//Extracting the values from the state
let units, amounts, multiples, quantity, name = this.state
// Inserting the values into the new ingredient
let ingredient = units, amounts, multiples, quantity, name
// Creating the copy
let ingredients = [ ... this.state.ingredients ]
// add the ingredient object into the ingredients array ( which is a property of state)
ingredients.push(ingredient);
// set the new array of ingredients in the state
this.setState(ingredients);
;
answered Mar 9 at 17:23
mthrsjmthrsj
1,6541724
1,6541724
Thank you so much for taking the time to explain that !I knew my methods were not working correctly, but was not sure how to fix them. I will try this right away !
– Christina Roberts
Mar 9 at 17:49
@ChristinaRoberts, you're welcome! I recommend to you to check if all the other handles are working as expected, also.
– mthrsj
Mar 9 at 17:54
that fixed my problem of being able to add the ingredients, but now further down, the post request is still not working. I am VERY new to the javascript and react side of things so its still a challenge to turn my logic (backend style) into valid javascript code haha
– Christina Roberts
Mar 9 at 18:16
@ChristinaRoberts, as this answer solves your problem of ingredients field being empty, feel free to mark it as solution. If is there any other problem, not related with the first one, I recommend you to ask a new question
– mthrsj
Mar 10 at 11:54
add a comment |
Thank you so much for taking the time to explain that !I knew my methods were not working correctly, but was not sure how to fix them. I will try this right away !
– Christina Roberts
Mar 9 at 17:49
@ChristinaRoberts, you're welcome! I recommend to you to check if all the other handles are working as expected, also.
– mthrsj
Mar 9 at 17:54
that fixed my problem of being able to add the ingredients, but now further down, the post request is still not working. I am VERY new to the javascript and react side of things so its still a challenge to turn my logic (backend style) into valid javascript code haha
– Christina Roberts
Mar 9 at 18:16
@ChristinaRoberts, as this answer solves your problem of ingredients field being empty, feel free to mark it as solution. If is there any other problem, not related with the first one, I recommend you to ask a new question
– mthrsj
Mar 10 at 11:54
Thank you so much for taking the time to explain that !I knew my methods were not working correctly, but was not sure how to fix them. I will try this right away !
– Christina Roberts
Mar 9 at 17:49
Thank you so much for taking the time to explain that !I knew my methods were not working correctly, but was not sure how to fix them. I will try this right away !
– Christina Roberts
Mar 9 at 17:49
@ChristinaRoberts, you're welcome! I recommend to you to check if all the other handles are working as expected, also.
– mthrsj
Mar 9 at 17:54
@ChristinaRoberts, you're welcome! I recommend to you to check if all the other handles are working as expected, also.
– mthrsj
Mar 9 at 17:54
that fixed my problem of being able to add the ingredients, but now further down, the post request is still not working. I am VERY new to the javascript and react side of things so its still a challenge to turn my logic (backend style) into valid javascript code haha
– Christina Roberts
Mar 9 at 18:16
that fixed my problem of being able to add the ingredients, but now further down, the post request is still not working. I am VERY new to the javascript and react side of things so its still a challenge to turn my logic (backend style) into valid javascript code haha
– Christina Roberts
Mar 9 at 18:16
@ChristinaRoberts, as this answer solves your problem of ingredients field being empty, feel free to mark it as solution. If is there any other problem, not related with the first one, I recommend you to ask a new question
– mthrsj
Mar 10 at 11:54
@ChristinaRoberts, as this answer solves your problem of ingredients field being empty, feel free to mark it as solution. If is there any other problem, not related with the first one, I recommend you to ask a new question
– mthrsj
Mar 10 at 11:54
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55072890%2fproperties-of-state-not-setting-this-field-is-required%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
try to console.log your
this.state.ingredients
and look what's there when you add a new ingredient. Maybe the result isn't what you was expecting– mthrsj
Mar 9 at 1:39
It is empty. My handleIngredientInput method is not doing what I expected. I am unsure of the syntax to make the logic I want work correctly. DO you have any advice ?
– Christina Roberts
Mar 9 at 11:35