add warning message if vote than 2

This commit is contained in:
nurafrinaalimi16
2024-04-17 15:21:46 +08:00
parent a2f4c00495
commit 076d0cbb07
@@ -161,21 +161,25 @@ export default {
selected[i]['nominee_id'] = null; selected[i]['nominee_id'] = null;
} }
}, },
vote: function (position_id, nominee_id) { vote: function (position_id, nominee_id) {
if (!this.selected[0]['position_id']) { if (!this.selected[0]['position_id']) {
this.$set(this.selected[0], position_id, []); this.$set(this.selected[0], position_id, []);
} }
const index = this.selected[0]['nominee_id'].indexOf(nominee_id); const index = this.selected[0]['nominee_id'].indexOf(nominee_id);
if (index === -1) { if (index === -1) {
// Nominee not found, add it // Nominee not found, add it
this.selected[0]['nominee_id'].push(nominee_id); if (this.selected[0]['nominee_id'].length < 2) {
} else { this.selected[0]['nominee_id'].push(nominee_id);
// Nominee found, remove it } else {
this.selected[0]['nominee_id'].splice(index, 1); // Display warning message if more than 2 nominees are selected
} this.util.notify('Boleh mengundi (2) calon sahaja!', 'warning');
console.log(this.selected[0]) }
}, } else {
// Nominee found, remove it
this.selected[0]['nominee_id'].splice(index, 1);
}
console.log(this.selected[0])
},
getSelectedNomineeName: function (id) { getSelectedNomineeName: function (id) {
return this.getNominee(id); return this.getNominee(id);