Struggling to update a calendar using the Datepicker component with Vue.js, I encountered some issues with adding and deleting items (specifically Date objects)
I have written two javascript functions: one for adding new Dates to an array, and another for removing specific dates from the same array. The problem arises when trying to add a date and then delete it without reloading the website, as the function returns -1 when searching for the index of the date in the array.
addDate: function(event) {
var fecha = document.getElementById("inputFecha").value;
var fecha2 = new Date(fecha);
availableDates.push(fecha2);
},
deleteDate: function(event) {
var collection = availableDates,
d = new Date(event.getFullYear(), event.getMonth(), event.getDate()),
idx;
idx = collection.map(Number).indexOf(+d);
if(idx!=-1){
availableDates.splice(idx,1);
}
}
Here are some of the initial dates created in the file:
var availableDates = [];
availableDates.push(new Date(2019, 2, 29));
availableDates.push(new Date(2019, 2, 30));
availableDates.push(new Date(2019, 2, 28));
The goal is to enable adding and deleting functionality without needing to refresh the website.