Skip to content

Commit 2b74447

Browse files
committed
Applying feedback
Removed css file. Replaced `products` with `brands` in service. Some minor changes.
1 parent b79f87d commit 2b74447

4 files changed

Lines changed: 18 additions & 40 deletions

File tree

samples/jquery/00 ShoppingForm/src/css/site.css

Lines changed: 0 additions & 21 deletions
This file was deleted.

samples/jquery/00 ShoppingForm/src/modules/app/app.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class App {
3131
}
3232

3333
loadBrands() {
34-
productsService.fetchProducts()
34+
productsService.fetchBrands()
3535
.then(fetchedProducts => {
3636
this.brands = fetchedProducts;
3737
this.loadSelect($selBrands, this.brands);
@@ -75,15 +75,15 @@ class App {
7575
}
7676
}
7777

78-
loadProductsByBrand(id) {
79-
if (id !== null) {
80-
const osList = this.getProductsByBrand(id);
81-
this.loadSelect($selProducts, osList);
78+
loadProductsByBrand(brand) {
79+
if (brand !== null) {
80+
const products = this.getProductsByBrand(brand);
81+
this.loadSelect($selProducts, products);
8282
}
8383
}
8484

8585
getProductsByBrand(id) {
86-
const brand = this.brands.filter(product => product.id === id);
86+
const brand = this.brands.filter(brand => brand.id === id);
8787
return brand[0] && brand[0].products;
8888
}
8989

@@ -107,24 +107,26 @@ class App {
107107
getModel($form) {
108108
return $form
109109
.serializeArray()
110+
110111
// from { name: <prop>, value: <val> } to [<prop>, <val>] }
111112
.map(field => ({ [field.name]: field.value }))
113+
112114
// reduce all in an object
113115
.reduce((vm, field) => ({ ...vm, ...field }), {});
114-
};
116+
}
115117

116118
handleFieldValidationResult($form) {
117-
return (function (fieldValidationResult) {
119+
return (fieldValidationResult) => {
118120
const field = $form.get(0)[fieldValidationResult.key];
119121
this.toggleErrorMessage(fieldValidationResult, $(field));
120-
}).bind(this);
122+
};
121123
}
122124

123125
onFieldChange(event) {
124126
const $field = $(event.currentTarget);
125127
productsFormValidation
126128
.validateField(null, $field.attr('name'), $field.val(), { onChange: true })
127-
.then((validationResult) => {
129+
.then(validationResult => {
128130
this.toggleErrorMessage(validationResult, $field);
129131
})
130132
.catch(error => {
@@ -148,5 +150,5 @@ class App {
148150
}
149151

150152
export {
151-
App,
153+
App
152154
};

samples/jquery/00 ShoppingForm/src/modules/app/validation/rules/nifValidator.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ function validateNif(value) {
2828
.replace(/^[Z]/, '2');
2929
const letter = valueToUpper.substr(-1);
3030
const charIndex = parseInt(nie.substr(0, 8)) % 23;
31-
32-
if (validChars.charAt(charIndex) === letter) {
33-
isValid = true;
34-
}
31+
isValid = (validChars.charAt(charIndex) === letter);
3532
}
3633

3734
return isValid;

samples/jquery/00 ShoppingForm/src/services/productsService.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const products = [
1+
const brands = [
22
{
33
id: 18,
44
description: 'Corsair',
@@ -59,10 +59,10 @@ const products = [
5959
},
6060
];
6161

62-
function fetchProducts() {
63-
return Promise.resolve(products);
62+
function fetchBrands() {
63+
return Promise.resolve(brands);
6464
}
6565

6666
export const productsService = {
67-
fetchProducts,
67+
fetchBrands,
6868
};

0 commit comments

Comments
 (0)