0

I have enabled/used the date picker from materializecss.com in my google script. I want to add a limit so that if a certain date is selected, for example, 10 times (e.g. 10 users selected the same date), it will disable the date selection.

I have placed the code for HTML for date picker which I got from materialize CSS. Then I also copy-paste the initialization indicated in the materialize CSS website under form then, picker and add some other codes.

for html:

<!-- DATE SELECTION -->
<div class="row">
   <div class="input-field col s4">
        <input id="subDate" type="text" class="datepicker" required>
        <label for="subDate">Select Date</label>
   </div> <!-- CLOSE TIME FIELD -->
</div>

for javascript:

document.addEventListener('DOMContentLoaded', function() { 
    //FOR DATE SELECTION
    var dateSelect = document.getElementById('subDate');
    // ----------- Setting Dates to Disable ------------
    var disabledDays = [
        new Date("2019, 11, 01").valueOf(), 
        new Date("2019, 7, 18").valueOf()
    ];

    M.Datepicker.init(dateSelect, {
       minDate: new Date ("2019, 5, 10"), 
       maxDate: new Date ("2019, 8, 21"), 
       format: 'mmmm dd, yyyy',
       disableWeekends: true,
       disableDayFn: function(day){
            return disabledDays.indexOf(day.valueOf()) > -1;
       }
     });
});

For now, I can select or pick dates but I don't know how to code for the limit. Thank you in advance for the help. I'm a newbie when it comes to programming.

GPni
  • 143
  • 1
  • 14
  • _"I want to add a limit so that if a certain date is selected, for example, 10 times, it will disable the date selection"_ - Could you please clarify this? Do you mean that if the user selects this date 10 times? Do you mean that if 10 different users selected this date? It's also important to note whether you're talking about selecting the same date in 10 different date pickers or in 10 separate "date registrations". – icecub Jul 12 '19 at 01:09
  • My apologies. What I mean if 10 different users selected the same date, it will be disabled. Thank you so much, – GPni Jul 12 '19 at 01:15
  • Unfortunetely I'm not formilliar with google-apps-script. But I assume the approach would be the same as with any other language. I suppose the registered dates are stored somewhere. Like a database for example. You'll have to pull those dates out of there first. Probably using Ajax for example. Then count them and if any date is in there 10+ times, add it to the disabled list before initializing the datepicker. – icecub Jul 12 '19 at 01:22
  • No too familiar with Ajax. Anyway thank you for the idea. :) – GPni Jul 12 '19 at 01:38
  • Ajax is just an asynchronous Javascript callback function. Basically it requests (or sends) data to / from your server and embeds that into your website without the need for a browser refresh. It would even allow you to periodically check the dates in your database and disable any date "on the fly" while the user is registering. That can be useful if you have many users and 5 users happen to be trying to register the same date at the same time while you already have 8 set in your database for example. – icecub Jul 12 '19 at 01:51
  • @GlennPerey - were you able to find a desired solution for this or are still on the lookout? Seemed like an interesting problem to work on so thought to check in first :) If you're still looking, it would help clarify what 'icecub' indicated in the previous comments - are these user details, their date choices being stored somewhere? – Sourabh Choraria Oct 02 '19 at 12:35
  • @ Sourabh Choraria Yes, I have found a solution in this problem. It's here in this link: https://stackoverflow.com/questions/57139423/disable-dates-in-the-datepicker-based-on-values-from-the-google-sheet-using-goog I'm really not familiar with ajax since I'm just new in programming. :) – GPni Oct 04 '19 at 01:12

0 Answers0