PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Limit Value of Dropdown based on DayOfTheWeek selected from DatePicker

  1. Hi All.

    So have been playing with DatePicker and have managed to make "Requested Appointment Date" to now only allow Monday to Saturday as selectable days.

    See here: http://marymebridal.com/appointments/

    What I want to do next is based on the DayOfTheWeek of the selected date from the "Requested Appointment Date", I want to be able to then restrict the list values of the dropdown for "Requested Appointment Time".

    I have two sets of time based on Mon-Thu and Fri-Sat. So depending on the DOTW of the selected date, I want to be able to only show the relevant time slots.

    Any ideas on how I can easily achieve this? or at least point me in the right direction? Been looking at pre_render and post_render but no luck.

    Thanks in advance for any feedback and assistance.

    Posted 11 years ago on Thursday December 20, 2012 | Permalink
  2. Figured it out at the end using a bit of Jquery, JS and OOTB functionality from Gravity Forms.

    Created another field called Day Of The Week, but made it readonly prior to setting the value and post setting the value of the input field.

    Day Of The Week is then filled in based on selected date. See below.

    // Array for the name of the Weekday
    var weekday=new Array(7);
    weekday[0]="Sunday";
    weekday[1]="Monday";
    weekday[2]="Tuesday";
    weekday[3]="Wednesday";
    weekday[4]="Thursday";
    weekday[5]="Friday";
    weekday[6]="Saturday";

    // set Day Of The Week field to readonly prior to picking a date
    jQuery("#input_1_18").attr("readonly", true);

    // On select of a date in datepicker move value to Day Of The Week
    jQuery("#input_1_7").change(function(){

    var date = jQuery("#input_1_7").datepicker('getDate');
    var dayOfWeek = weekday[date.getUTCDay()];

    // Make Day Of The Week editable
    jQuery("#input_1_18").attr("readonly", false);
    // Set Day Of The Week but emulate keyup
    jQuery("#input_1_18").val(dayOfWeek).keyup();
    // Make Day Of The Week readonly again so users cant change it
    jQuery("#input_1_18").attr("readonly", true);

    });

    I just used the OOTB gravity forms functionality to then show the required Appointment Time dropdown list based on value of Day Of The Week (Mon-Thu vs Fri-Sat). The trick is to emulate a user entering the Day Of The Week, otherwise, Gravity Forms won't trigger the condition. Hence, added .keyup after setting the field value and Voila! It works great!

    Might be an easier way and more efficient way of doing this, but ho-hum.

    Posted 11 years ago on Friday December 21, 2012 | Permalink
  3. Thank you for posting your solution.

    Posted 11 years ago on Friday December 21, 2012 | Permalink

This topic has been resolved and has been closed to new replies.