Jump to content

Harpreet

Caspio Ninja
  • Posts

    33
  • Joined

  • Last visited

Reputation Activity

  1. Like
    Harpreet reacted to futurist in Regarding constraint on date   
    Hi @Harpreet,
    am i right in understanding that you want to prevent your users from selecting previous dates from last week, correct? so only the monday of the current week and the future dates should be selected.

    I did this workaround where I created another date field wherein the popup calendar blocks the previous date from the previous weeks. 
     
    https://c1hch576.caspio.com/dp/db26a0007065f385f52745b28b16
    What i did was add an HTML block and paste this:
    Date : <input id="date_picker" type="date" onchange="myFunction()">
    This is going to act like a substitute for the actual date field. You would need to hide the actual date field by setting the form element to "Hidden"
    Add a Header and Footer. Disable the HTML editor for both. On the Header, paste the ff:
     <script type="text/javascript" src="https://code.jquery.com/jquery-1.7.2.min.js"></script>
     
    On the Footer, paste the ff:
    <script language="javascript">
    function myFunction() {
      var x = document.getElementById("date_picker").value;
    var myarr = x.split("-");
    var samedate =  myarr[1] + "/" + myarr[2] + "/" + myarr[0];
      document.getElementById("InsertRecordField_Date").value = samedate;
    }
    function getMonday(d) {
      d = new Date(d);
      var day = d.getDay(),
          diff = d.getDate() - day + (day == 0 ? -6:1); // adjust when day is sunday
      return new Date(d.setDate(diff));
    }

    let yourDate = getMonday(new Date())
        $('#date_picker').attr('min', yourDate.toISOString().split('T')[0]);

    </script>
    Wherein "InsertRecordField_Date" refers to my actual date field. Change the "Field_Date" to whatever is the name of your actual field date. Keep the "InsertRecord" prefix.
     
    Basically what transpires is, your user is actually going to see the date field you added instead of your actual date field, and what the script I provided is going to do is, whatever date a user selects on the substitute field, that date will also be placed on the actual date field. The script also ensures that the previous dates from previous weeks cannot be selected on the substitute field's calendar popup, and that only the monday of the current week onwards are available. 
    When they hit Submit, the date should still reflect on your table.
     
×
×
  • Create New...