0

I am working on an appointment system where you can select multiple dates in a month and then submit it as data base as an array. When you click on a date in fullcalender,

You will see on a eg 20-03, 24-03, 25-03 depending on the number of dates selected

On posting it, to database, it will be date=[20-03, 24-03, 25-03]

The problem is that when i click on date, it is not organized into array and it is not formatted.

   ` <div id='calendar'></div>
 
            <label for="dates">Dates</label>
            <input  name="date" value= readonly>
    
      <script src='https://cdn.jsdelivr.net/npm/fullcalendar@6.1.4/index.global.min.js'></script>
        <script>
  
        document.addEventListener('DOMContentLoaded', function() {
            var calendarEl = document.getElementById('calendar');
                var calendar = new FullCalendar.Calendar(calendarEl, {
                
            headerToolbar: {
                start:   'title',
                center: '',
                end: ''
        
                    },
    
              initialView: 'dayGridMonth',
            selectable: true,
            
            
             dateClick: function(info) {
  
   if(selected.includes(info.dateStr)){
    selected.pop(info.dateStr);
   } 
   else{
    selected.push(info.dateStr);
   }
document.getElementById("dates").value =selected;
  
},
    
           
        
            }
        });
    
   document.getElementById('month').addEventListener('change', function() {
      var date = document.getElementById('month').value;
      console.log(date);
        calendar.gotoDate( date );
      
    });
    
        calendar.render();
    });
        </script>`

i have tried to use fullcalender ->formate() to formate selected date, but it doesnt work. I tried to use moment().formate(), it doesnt work. I have added selected to fullcalender but i cant select or deselect multiple dates

upcoming
  • 11
  • 7
  • fullcalendar doesn't support selection of multiple, non-consecutive dates – ADyson Mar 10 '23 at 01:28
  • No idea what `selected = [date.start, + date.start++];` is supposed to mean, that's not valid JS – ADyson Mar 10 '23 at 01:29
  • 1
    `fullcalender ->formate()`...there is no such function. https://fullcalendar.io/docs#toc . `moment().formate()`...there is no such function. (Well, there is, but you [spelled it wrong](https://momentjs.com/docs/#/displaying/format/)) – ADyson Mar 10 '23 at 01:30
  • 1
    This might help you: https://stackoverflow.com/questions/29181823/how-to-select-multiple-date-ranges-from-fullcalendar (the code is for fullCalendar 3, but the principle still applies, and you can just adapt the code for the newer version) – ADyson Mar 10 '23 at 01:31
  • @ADyson thanks for your answer. selected = [date.start, + date.start++]; I tried to see if it will get selected dates into array. Is there no API or any way multiple dates can be selected buy users ? – upcoming Mar 10 '23 at 11:40
  • 1
    There's nothing in the API, except you can already drag to select multiple days if they are consecutive. If you want to select multiple non-consecutive dates then you need to build your own functionality for that. At the most basic level it would probably involve tracking the date ranges selected, and adding them to a separate array. `I tried to see if it will get selected dates into array`...well that's a good idea, but it seems you need to learn basic JavaScript syntax in order to achieve that, I have no idea what you think all those `+`s are for? – ADyson Mar 10 '23 at 11:52
  • @ADyson thanks for your guide. I did it with dateClick and javascript. But i have little challenge. I want when a date is clicked, it will add into array. When same date is clicked again, it will be removed from the array. But the problem is that second click remove the last added date in the array and not the date that was clicked. – upcoming Mar 10 '23 at 20:53
  • 1
    You need to [find the index of the array where it was included, and then remove the entry at that index](https://stackoverflow.com/questions/5767325/how-can-i-remove-a-specific-item-from-an-array-in-javascript) – ADyson Mar 10 '23 at 23:51

0 Answers0