Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions exercises.html

This file was deleted.

60 changes: 25 additions & 35 deletions food.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@
/* 0 */
/***/ (function(module, exports, __webpack_require__) {

const $ = __webpack_require__(1);
const host = 'https://q-self-api.herokuapp.com/api/foods';
const Validations = __webpack_require__(1);
const $ = __webpack_require__(2);

$(document).ready(function () {
fetchFoods();
Expand Down Expand Up @@ -95,14 +94,37 @@
$(".food-options tbody").prepend(foodRow);
};

function handleFieldErrors(newFood) {
clearErrors();
checkForName(newFood['name']);
checkForCalories(newFood['calories']);
};

function checkForName(name) {
if (!name) {
$('.name-validation-error').html('Please enter a food name');
};
};

function checkForCalories(calories) {
if (!calories) {
$('.calories-validation-error').html('Please enter a calorie amount');
};
};

function clearErrors() {
$('.name-validation-error').empty();
$('.calories-validation-error').empty();
};

function handleNewFood() {
event.preventDefault();
$newFood = new Object();

$newFood['name'] = $("input[name=food-name]").val();
$newFood['calories'] = $("input[name=food-calories]").val();

Validations.handleFieldErrors($newFood);
handleFieldErrors($newFood);

const finalForm = { food: $newFood };
$.ajax({
Expand Down Expand Up @@ -225,38 +247,6 @@

/***/ }),
/* 1 */
/***/ (function(module, exports) {

class Validations {

static handleFieldErrors(newFood) {
this.clearErrors();
this.checkForName(newFood['name']);
this.checkForCalories(newFood['calories']);
}

static checkForName(name) {
if (!name) {
$('.name-validation-error').html('Please enter a food name');
};
}

static checkForCalories(calories) {
if (!calories) {
$('.calories-validation-error').html('Please enter a calorie amount');
};
}

static clearErrors() {
$('.name-validation-error').empty();
$('.calories-validation-error').empty();
}
}

module.exports = Validations;

/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {

var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
Expand Down
11 changes: 3 additions & 8 deletions foods.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ <h1 class="center">Manage Foods</h1>
<form class="new-food">
<fieldset>
<label id="name-field" class="center" for="name-field">Name</label>
<input type="text" placeholder="Pistachios" name="food-name">
<input id="add-name" type="text" placeholder="Pistachios" name="food-name">
<div class="error name-validation-error"></div>

<label id="calories-field" class="center" for="colorie-amount">Calorie Amount</label>
<input type="text" placeholder="10,000" name="food-calories">
<input id ="add-calories" type="text" placeholder="10,000" name="food-calories">
<div class="error calories-validation-error"></div>

<div class="container">
Expand Down Expand Up @@ -50,11 +50,6 @@ <h1 class="center">Manage Foods</h1>
</div>
</div>
</div>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous">
</script>
<script src="./lib/foods.js"></script>
<script src="food.bundle.js"></script>
</body>
</html>
6 changes: 4 additions & 2 deletions lib/foods.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const host = 'https://q-self-api.herokuapp.com/api/foods'
const $ = require('jquery');
const host = 'http://localhost:3000/api/foods'
// const host = 'https://q-self-api.herokuapp.com/api/foods'

$(document).ready(function() {
fetchFoods();
Expand Down Expand Up @@ -41,7 +43,7 @@ function populateTable () {

function addRow(food) {
let foodRow = `
<tr class='food' id=${food.id}>
<tr class='food ${food.name}' id=${food.id} >
<td class='food-name'>${food.name}</td>
<td class='food-calories'>${food.calories}</td>
<td class='food-delete'><i class="material-icons" id=${food.id}>remove_circle</i></td>
Expand Down
Loading