From 076d0cbb073e7d8c55c579b0b447dc754066b0d6 Mon Sep 17 00:00:00 2001 From: nurafrinaalimi16 Date: Wed, 17 Apr 2024 15:21:46 +0800 Subject: [PATCH] add warning message if vote than 2 --- .../js/components/demo/voter/home/vote.vue | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/resources/assets/js/components/demo/voter/home/vote.vue b/resources/assets/js/components/demo/voter/home/vote.vue index bea47dc..20386cd 100644 --- a/resources/assets/js/components/demo/voter/home/vote.vue +++ b/resources/assets/js/components/demo/voter/home/vote.vue @@ -161,21 +161,25 @@ export default { selected[i]['nominee_id'] = null; } }, - vote: function (position_id, nominee_id) { - if (!this.selected[0]['position_id']) { - this.$set(this.selected[0], position_id, []); - } - const index = this.selected[0]['nominee_id'].indexOf(nominee_id); - if (index === -1) { - // Nominee not found, add it - this.selected[0]['nominee_id'].push(nominee_id); - } else { - // Nominee found, remove it - this.selected[0]['nominee_id'].splice(index, 1); - } - console.log(this.selected[0]) - }, + if (!this.selected[0]['position_id']) { + this.$set(this.selected[0], position_id, []); + } + const index = this.selected[0]['nominee_id'].indexOf(nominee_id); + if (index === -1) { + // Nominee not found, add it + if (this.selected[0]['nominee_id'].length < 2) { + this.selected[0]['nominee_id'].push(nominee_id); + } else { + // Display warning message if more than 2 nominees are selected + this.util.notify('Boleh mengundi (2) calon sahaja!', 'warning'); + } + } else { + // Nominee found, remove it + this.selected[0]['nominee_id'].splice(index, 1); + } + console.log(this.selected[0]) + }, getSelectedNomineeName: function (id) { return this.getNominee(id);