From d95677ab57d0aabf248ad709d00d4a505c6e2283 Mon Sep 17 00:00:00 2001 From: Raphael LACOTE Date: Thu, 9 Mar 2023 20:00:52 +0100 Subject: [PATCH] Rectification d'un bug sur les liaisons et ajout de gestions d'erreurs sur la taille des strings --- index.html | 27 ++++++++++++++------------- src/error/string_size.js | 5 +++++ src/misc/constant.js | 4 +++- src/view/team_add.js | 17 +++++++++++------ 4 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 src/error/string_size.js diff --git a/index.html b/index.html index f202fa7..6a36862 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ My awesome team - + @@ -16,39 +16,40 @@ + :id="team.id" + :name="team.name" + :description="team.description"> + diff --git a/src/error/string_size.js b/src/error/string_size.js new file mode 100644 index 0000000..96f207e --- /dev/null +++ b/src/error/string_size.js @@ -0,0 +1,5 @@ +class StringSize extends Error { + constructor(field,sSize) { + super('Le champ ' + field + ' doit avoir une taille superieur à '+sSize); + } +} \ No newline at end of file diff --git a/src/misc/constant.js b/src/misc/constant.js index 322ba48..c1c9af9 100644 --- a/src/misc/constant.js +++ b/src/misc/constant.js @@ -1 +1,3 @@ -const ERROR_COLOR = 'red'; \ No newline at end of file +const ERROR_COLOR = 'red'; +const DESCRIPTION_MINIMAL_SIZE = 20; +const NAME_MINIMAL_SIZE = 5; \ No newline at end of file diff --git a/src/view/team_add.js b/src/view/team_add.js index 1ff54cd..f38e343 100644 --- a/src/view/team_add.js +++ b/src/view/team_add.js @@ -13,23 +13,25 @@ export default { try { this.errorMessage = ''; if (!this.id) { - this.name = ''; - this.description= ''; throw new RequiredFieldError("ID"); return; } if (!this.name) { - this.id = ''; - this.description= ''; throw new RequiredFieldError("Name"); return; } if (!this.description){ - this.id = ''; - this.name = ''; throw new RequiredFieldError("Description"); return; } + if (this.description.length < DESCRIPTION_MINIMAL_SIZE) { + throw new StringSize("Description", DESCRIPTION_MINIMAL_SIZE) + } + if (this.name.length < NAME_MINIMAL_SIZE) { + throw new StringSize("Name", NAME_MINIMAL_SIZE) + } + + console.log(this.description.length) const team = { id: this.id, name: this.name, description: this.description}; console.log('form.addTeam', team); @@ -43,6 +45,9 @@ export default { if (error instanceof RequiredFieldError) { this.errorMessage=error } + if (error instanceof StringSize) { + this.errorMessage = error + } return null; } }