Customizing Date Pickers - InfoPath Dev
in

InfoPath Dev

Customizing Date Pickers

Last post 04-28-2008 05:07 AM by zeroecho. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 10-23-2007 05:41 AM

    • zeroecho
    • Top 500 Contributor
      Male
    • Joined on 10-23-2007
    • Yorkshire, UK
    • Posts 39

    Customizing Date Pickers

    Hello All,

    Firstly I just want to say this forum is brilliant, it's already helped me solve problems I was unable to find solutions to elsewhere on the www.

    My current problems are two different issues based around dates. I am developing in WSS (not MOSS... yet) and InfoPath07

    I am developing a timesheet form which asks the user to select the date the week begins on. There are then read-only date fields above each "Day of the week" label (which are columns in a repeating table) eg "23/10/07" above Tuesday. in the hope that I can somehow figure out how to pull the information for all of Tuesdays activities as well as being able to track activities/tasks are rows of that repeating table

    So, the problem is that these date labels are all based off the date the user enters, so if the user selected that the week began on Tues 23rd Oct 07, then the labels would show Monday with 23rd Oct 07 above it. I cannot find a way to only let the Date Picker for the "Week beginning..." date only allow the user to select a Monday. If I could then the rest would always be displayed correctly

    The other hope was that rather than having got the date values based on the "Week beginning..." date, that the current setup of having one row for 22/10, 23/10, 24/10, 25/10, 26/10, 27/10 with M, Tu, W, Th, F etc. underneath on a seperate row, would be that based upon the date e.g. 22/10 that the display value would be Mon for that date instead, but the underlying xml value saves the actual date.

    Image Hosted by ImageShack.us

    I figure there must be some way to do this without having to mess around with Visual Studio? Am I being blind and missing a function/formula to have rules for the date box to stop any date except Monday being entered? And am I being blind missing an option to display the Date as a Dayname tied to that date??

    Thank you for your help in advance and I hope I have explained the problem sufficiently

  • 10-23-2007 01:09 PM In reply to

    Re: Customizing Date Pickers

    Hello and welcome to our forum! Your question is also one we struggle with as it is a very common scenario. What you want to do unfortunately requires code. InfoPath doesn't have any built-in functions for getting the week start date. Sorry for that bad news.

    Shiraz Cupala / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 10-23-2007 01:47 PM In reply to

    • zeroecho
    • Top 500 Contributor
      Male
    • Joined on 10-23-2007
    • Yorkshire, UK
    • Posts 39

    Re: Customizing Date Pickers

    Thank you for your reply Shiraz, even if it is a bit of bad news for me!

     
    Are there any links you know of which describe how to go about doing it in code, and if I do something in code for an infopath form, will it still be browser compatible?

    Also, I was told that to use InfoPath forms as part of SP that you need both Standard CALs AND Enterprise CALs to fill the forms out without infopath installed on the clients PC, just wanted to double check do you know if that is correct?

    Thank you again for your help!
     

  • 10-23-2007 02:09 PM In reply to

    Re: Customizing Date Pickers

    hi

    Sorry to be the bearer of yet more bad news but browser forms are not compatible with code.  You do need Infopath to view non-browser forms, or InfoPath forms services.  One other solution is Qdabra's forms viewer which enables limited functionality but an InfoPath like browser form.

     hope this helps

    Cheers

    Adam Harding
    Wales
    UK
  • 10-24-2007 02:21 AM In reply to

    • zeroecho
    • Top 500 Contributor
      Male
    • Joined on 10-23-2007
    • Yorkshire, UK
    • Posts 39

    Re: Customizing Date Pickers

    Thanks Adam,

    I need to avoid code then it seems.

    Would asking the user to enter the week number instead work? Then have some formula in the date field above Monday which works out based upon week number and year as to what date the week would begin on? I wonder if there is a webservice out there which holds this kind of data out there I could query to return the date based upon week number entered. Still not ideal though as the user has to then know which week of the year they are in!

    Thoughts anyone?
     

  • 10-24-2007 10:52 AM In reply to

    Re: Customizing Date Pickers

    OK

    You could work it differently anchange it to a combo box or a drop-down list that just has the available Mondays in it, you could generate a list in Excel or Access and copy it into InfoPath, that would provide a complete limited list

    Cheers

    Adam Harding
    Wales
    UK
  • 10-26-2007 03:03 AM In reply to

    • zeroecho
    • Top 500 Contributor
      Male
    • Joined on 10-23-2007
    • Yorkshire, UK
    • Posts 39

    Re: Customizing Date Pickers

     Thanks Adam, I had actually already done that in excel before you're reply but thought it was a bit fugly hehe, but it will do the job and I might be able to do some customizing of the view/programming in sharepoint to automatically update that list so that only X months into the past and future we displayed.

    Thanks for all your help/comments.

     

  • 04-28-2008 05:07 AM In reply to

    • zeroecho
    • Top 500 Contributor
      Male
    • Joined on 10-23-2007
    • Yorkshire, UK
    • Posts 39

    Re: Customizing Date Pickers

    As a follow up to this, I went down the code route and got it to work this way

     

            public void FormEvents_Loading(object sender, LoadingEventArgs e)
            {
                XPathNavigator domNav = MainDataSource.CreateNavigator();

                if (domNav.SelectSingleNode("/my:TimesheetDetails/my:EmployeeInformation/my:WeekOf", NamespaceManager).Value == "")
                {
                    DateTime today = DateTime.Today;
                    //today = today.ToUniversalTime();
                    DateTime weekStart = firstDayOfWk(today);
                    int year = weekStart.Year;
                    string date = firstDayOfWk(today).ToShortDateString();
                    date = date.Substring(0, 2);
                    string month = firstDayOfWk(today).ToShortDateString();
                    month = month.Substring(3, 2);
                    string weekStartString = year + "-" + month + "-" + date;
                    domNav.SelectSingleNode("/my:TimesheetDetails/my:EmployeeInformation/my:WeekOf", NamespaceManager).SetValue(weekStartString);
                }

            } 

     

         public static DateTime firstDayOfWk(DateTime dt)
            {
                double daysToSubtract = 0;

                switch (dt.DayOfWeek)
                {
                    case (DayOfWeek.Sunday):
                        daysToSubtract = 6;
                        break;
                    case (DayOfWeek.Friday):
                        daysToSubtract = 4;
                        break;
                    case (DayOfWeek.Monday):
                        daysToSubtract = 0;
                        break;
                    case (DayOfWeek.Saturday):
                        daysToSubtract = 5;
                        break;
                    case (DayOfWeek.Thursday):
                        daysToSubtract = 3;
                        break;
                    case (DayOfWeek.Tuesday):
                        daysToSubtract = 1;
                        break;
                    case (DayOfWeek.Wednesday):
                        daysToSubtract = 2;
                        break;
                }
                return dt.AddDays(-daysToSubtract);
            }

     

    This uses a list of dates worked out in excel and uploaded to sharepoint, and then based upon today's date, finds the previous Monday (unless today is Monday, then it gets today's date!) This still gives users the option of choosing Mondays in the past or future for their timesheet.

Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.