Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Neel317 committed Oct 17, 2023
2 parents c60e5bc + 728c940 commit 839b3fb
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Code/frontend/src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class Form extends Component {
addHandler = (event) => {
const ingredient = document.getElementById("ingredient").value;

if (ingredient.trim() === "") {
alert("Ingredient cannot be empty");
return;
}

this.setState(
{
//cuisine : this.state.cuisine,
Expand Down Expand Up @@ -103,6 +108,16 @@ class Form extends Component {
const budget = document.getElementById("budget").value;
const time = document.getElementById("time_to_cook").value

if (isNaN(budget) || budget <= 0) {
alert("Budget should be a positive number");
return;
}

if (isNaN(time) || time <= 0) {
alert("Time to cook should be a positive number");
return;
}

const response = await recipeDB
.get(`/recipes?CleanedIngredients=${this.state.ingredients}&Cuisine=${this.state.ingredients}&budget=${budget}&TotalTimeInMins=${time}`)
.catch((err) => {
Expand Down Expand Up @@ -134,6 +149,11 @@ class Form extends Component {
() => console.log(this.state)
);

if (this.state.cuisine.trim() === "") {
alert("Cuisine cannot be empty");
return;
}

event.preventDefault();
var dict = {};
dict["ingredient"] = this.state.ingredients;
Expand Down

0 comments on commit 839b3fb

Please sign in to comment.