limit date choice in Date Picker - InfoPath Dev
in

InfoPath Dev

limit date choice in Date Picker

Last post 04-24-2007 05:01 AM by nukkumatti. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 04-24-2007 03:18 AM

    • alex.1
    • Not Ranked
    • Joined on 04-24-2007
    • Posts 1

    limit date choice in Date Picker

    Hallo,

     I would like to disable choice of weekend-days in Date Picker.

    Alex 

     

  • 04-24-2007 04:55 AM In reply to

    Re: limit date choice in Date Picker

    This is a bit tricky but doable.

    The easiest would be to set the fromat of the datepicker to this representation of the date (e.g. Wednesday, March 14, 2007). Then you could check if there is "Saturday" or "Sunday" within the text of the xml node and then handle the wrong selection of the user. However this is not possible as the internal representation of a date is always 3/14/2007 for the above mentioned date.

    But there is a little workaround. I guess you have a Submit button on your form so double click it and select "Edit code". Now you can use the following code to check if some wrong day was selected (code is in C#):

    //store the selected date into a temp variable

    string tmp = thisXDocument.DOM.selectSingleNode("my:myFields/my:datepicker").text;

    //convert the date string stored in your temp variable to the date format you need to do the check

    string tmp = thisXDocument.DOM.selectSingleNode("my:myFields/my:datepicker").text;

    //convert the date string stored in your temp variable to the date format you need to do the check

    //convert the date string stored in your temp variable to the date format you need to do the check

    string convertedTime = Convert.ToDateTime(tmp).ToString("dddd, MMMM dd yyyy");

    //get only the day fromt the complete date (Wedenesday, March 14, 2007)

    string convertedTime = Convert.ToDateTime(tmp).ToString("dddd, MMMM dd yyyy");

    //get only the day fromt the complete date (Wedenesday, March 14, 2007)

    //get only the day fromt the complete date (Wedenesday, March 14, 2007)

    string day = convertedTime.Substring(0, convertedTime.IndexOf(","));

    //check if the selected day is either a Saturday or Sunday

    string day = convertedTime.Substring(0, convertedTime.IndexOf(","));

    //check if the selected day is either a Saturday or Sunday

    //check if the selected day is either a Saturday or Sunday

    if(day == "Saturday" || day == "Sunday")

    {

    //empty the datepicker control again

    if(day == "Saturday" || day == "Sunday")

    {

    //empty the datepicker control again

    //empty the datepicker control again

    thisXDocument.DOM.selectSingleNode("my:myFields/my:field3").text = "";

    //show message to the user that he/she did a wrong selection

    //show message to the user that he/she did a wrong selection

    thisXDocument.UI.Alert("You are not allowed to select a Saturday or Sunday ! Please make a new selection.");

    }

    Let me know if this helps you !?!

    Listen to Motörhead cos they play Rock'n Roll :)
  • 04-24-2007 05:01 AM In reply to

    Re: limit date choice in Date Picker

    Somehow the copy paste messed up my post so read each line only once :)
    Listen to Motörhead cos they play Rock'n Roll :)
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.