Merge remote-tracking branch 'origin/RaphouBranche' into dorian

# Conflicts:
#	index.html
#	src/view/navbar.js
#	src/view/team_add.js
master
dorian.hodin 2 years ago
commit a166676ac3

@ -1,2 +1,3 @@
# TP_JavaScript # TP_JavaScript
Développeurs: HODIN Dorian , LACOTE Raphaël

@ -22,7 +22,9 @@
</teamcard> </teamcard>
</div> </div>
<script src="/src/misc/constant.js"></script> <script src="./src/misc/constant.js"></script>
<script src="./src/error/required_field_error.js"></script>
<script type="module"> <script type="module">
import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'; import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js';

@ -0,0 +1,5 @@
class RequiredFieldError extends Error {
constructor(field) {
super('Le champ '+field+' est obligatoire !');
}
}

@ -9,19 +9,27 @@ export default {
} }
}, },
methods: { methods: {
addTeam: function() { addTeam: function () {
try {
this.errorMessage = ''; this.errorMessage = '';
if (!this.id ){ if (!this.id) {
this.errorMessage = 'ID is required !'; this.name = '';
this.description= '';
throw new RequiredFieldError("ID");
return; return;
}else if (!this.name){ }
this.errorMessage = 'Name is required !'; if (!this.name) {
return this.id = '';
}else if(!this.description) { this.description= '';
this.errorMessage = 'Description is required !'; throw new RequiredFieldError("Name");
return;
}
if (!this.description){
this.id = '';
this.name = '';
throw new RequiredFieldError("Description");
return; return;
} }
const team = { id: this.id, name: this.name, description: this.description}; const team = { id: this.id, name: this.name, description: this.description};
console.log('form.addTeam', team); console.log('form.addTeam', team);
@ -30,6 +38,13 @@ export default {
this.id = ''; this.id = '';
this.name = ''; this.name = '';
this.description = ''; this.description = '';
} catch (error) {
if (error instanceof RequiredFieldError) {
this.errorMessage=error
}
return null;
}
} }
}, },
template: `<section> template: `<section>

Loading…
Cancel
Save