diff --git a/src/error/required_field_error.js b/src/error/required_field_error.js
index 0d2f81a..24267c5 100644
--- a/src/error/required_field_error.js
+++ b/src/error/required_field_error.js
@@ -1,5 +1,5 @@
class RequiredFieldError extends Error {
constructor(field) {
- super('Le champ ${field} est obligatoire !');
+ super('Le champ '+field+' est obligatoire !');
}
}
\ No newline at end of file
diff --git a/src/view/navbar.js b/src/view/navbar.js
index 2074fc7..6e61d28 100644
--- a/src/view/navbar.js
+++ b/src/view/navbar.js
@@ -1,11 +1,10 @@
export default {
- template:`
- `
};
\ No newline at end of file
diff --git a/src/view/team_add.js b/src/view/team_add.js
index 33537fe..6c4a252 100644
--- a/src/view/team_add.js
+++ b/src/view/team_add.js
@@ -8,20 +8,32 @@ export default {
}
},
methods: {
- addTeam: function() {
- this.errorMessage = '';
- if (!this.id || !this.name) {
- this.errorMessage = 'ID and Name are required !';
- return;
- }
+ addTeam: function () {
+ try {
+ this.errorMessage = '';
+ if (!this.id) {
+ throw new RequiredFieldError("ID");
+ return;
+ }
+ if (!this.name) {
+ throw new RequiredFieldError("Name");
+ return;
+ }
+
+ const team = { id: this.id, name: this.name };
+ console.log('form.addTeam', team);
- const team = { id: this.id, name: this.name};
- console.log('form.addTeam', team);
+ this.$emit('addTeam', team);
- this.$emit('addTeam', team);
+ this.id = '';
+ this.name = '';
+ } catch (error) {
+ if (error instanceof RequiredFieldError) {
+ this.errorMessage=error
+ }
- this.id = '';
- this.name = '';
+ return null;
+ }
}
},
template: `