#1
  1. No Profile Picture
    Super Moderator
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,567
    Rep Power
    112

    Limit available days for jQuery's Datepicker


    Well, I've seen notes about beforeShowDay:, but not too sure on the handing my PHP array over, or maybe a way to build the same setup on jQuery's side.
    PHP Code:
    $arr[0] = [FALSEFALSETRUEFALSEFALSETRUEFALSE];
    $arr[1] = [FALSETRUEFALSEFALSEFALSEFALSEFALSE];
    $arr[2] = [TRUEFALSEFALSETRUEFALSEFALSEFALSE];
    $arr[3] = [FALSEFALSEFALSEFALSETRUEFALSETRUE]; 
    This defines the work days in a 4-week structure. The project is a "Request Off" type page. I simply want Datepicker to limit the selectable dates in the same format, but am apparently overlooking the setup.

    My initial thought was to have PHP build it since that's where I started, but the structure is the same, so would there be a better option to have jQuery apply such an available/selectable setup? The only option I would need to offer would be an offset which simply builds it in 4 different displays and just having the week being the offset.
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
  2. #2
  3. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,276
    Rep Power
    4193
    I don't really understand how your current array is supposed to work. I don't see any way to map those values to any particular day. You need a starting date of some sort in order to then apply your weekly boolean fields.

    For the jQuery UI's date picker though you just need to build a map of days and boolean values. You could do that in PHP then json_encode it to pass it to your javascript if that's what you want to do.
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  4. #3
  5. No Profile Picture
    Super Moderator
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,567
    Rep Power
    112
    For example, lets say the very first week of the year that starts Sunday, Dec. 31st, 2017 thru Saturday, Jan. 6th, 2018 is supposed to be the first week to display Enabled/Disabled days in relation to $arr[0], then adjust as each week goes by. Do you know if I can pull this off in an interval? My array is currently for the use of my script building a calendar via an HTML table structure, 4 weeks & 7 days, so that's why it got built as it did, but am thinking the only option I may have is the actual dates themselves. I'm probably off on this since I'm barely a JavaScript person, and usually just use it for Ajax. :-/

    Edit: Example number 5 seems to KINDA be in the area I'm leaning towards. It defines how to disable certain days of the week, but seems to be an "all or nothing" kinda thing, and I need to pull this off in more a weekly manner, based on those 4 defined weeks.
    How to Disable Dates in Jquery DatePicker - A Short Guide
    The date itself hasn't truly been the focus of my script, since what PHP has simply been building is an HTML table, so the way I have done everything else truly has nothing to do with the actual date. Just row/column based detailing.

    Another view of someone defining an reoccurring item. This example shows an "Every other" item like a payday. It is only an example for 1 day, so I'm not sure if this is even close to my 4-week structure.
    https://stackoverflow.com/questions/...-week-biweekly

    Added to define/reference even/odd week. This might be fair, but my twist is more mine being a 4-week structure/template.
    https://stackoverflow.com/questions/...ry-second-week
    Last edited by Triple_Nothing; November 22nd, 2018 at 08:35 AM.
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
  6. #4
  7. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,190
    Rep Power
    2012
    Would something like this be what you are thinking about: (code only for demonstration porpuse)
    PHP Code:
    beforeShowDay: function(date) {
      var 
    weekNumber getWeek(date);  // 1-52
      
    var arrWeekIdx weekNumber 4// 0-3

      
    var dayNumber date.getDay(); // 0-6 

      
    return arr[arrWeekIdx][dayNumber];


    From what I can see, you need to create your own function to find the week number.
    You also nee to be sure about the various indexing matching your setup.
  8. #5
  9. No Profile Picture
    Super Moderator
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,567
    Rep Power
    112
    I kinda understand the referencing. Did I add the definition of arr correctly so it simply returns/references a TRUE/FALSE to show the date?
    PHP Code:
    beforeShowDay: function(date) { 
      var 
    weekNumber getWeek(date);  // 1-52 
      
    var arrWeekIdx weekNumber 4// 0-3 
      
    var dayNumber date.getDay(); // 0-6
      
    var arr = [[FALSEFALSETRUEFALSEFALSETRUEFALSE],
                 [
    FALSETRUEFALSEFALSEFALSEFALSEFALSE],
                 [
    TRUEFALSEFALSETRUEFALSEFALSEFALSE],
                 [
    FALSEFALSEFALSEFALSETRUEFALSETRUE]];  
      return 
    arr[arrWeekIdx][dayNumber]; 

    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
  10. #6
  11. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,190
    Rep Power
    2012
    Originally Posted by Triple_Nothing
    I kinda understand the referencing. Did I add the definition of arr correctly so it simply returns/references a TRUE/FALSE to show the date?
    I think it should work, as soon you have implemented a working copy of the getWeek function.
    You might find examples of it by some searching. It should return the first week as index 0.

    Also have in mind the specification for beforeShowDay and that it require an array as return type. (Datepicker Widget | jQuery UI API Documentation)
    Last edited by MrFujin; November 25th, 2018 at 07:29 PM.

IMN logo majestic logo threadwatch logo seochat tools logo