Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Populating days of the week from user Selected date. Timesheet style

Avatar

Level 3

So I haven't touched Adobe or Java in over a year and am having trouble remembering a few things.

I have a weekly timesheet I am editing and am having some issues.

1. The User is to select the start date first, however i only want this to be a monday.

2. This date will then populate the columns with the day and date in this format "Monday, Jan 9"

For some reason I cannot get the fields to populate the way I want. Any help would be appreciated.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Just comment out the xfa.host.setFocus("$") line - you'll still get the popup and the field will be set to null.

But the whole point is to make the person pick a Monday, and if you need the date before anything else happens using the setFocus command is a good method. So yes, you can sort-of get stuck in a loop, but it's easy to get out of the loop by following the instructions and selecting a Monday.

Populating a dropdown box with all Mondays would be more of a pain for the person filling in the form I think - it's going to be a big dropdown list.

View solution in original post

4 Replies

Avatar

Level 10

I did a form like this recently using FormCalc.

You'll probably need to modify the code a bit. I haven't tested it, I just did a quick on-the-fly adaptation from the form I did - it used the ending date instead of the starting date so I was counting backwards instead of forwards. I was also using two tables.

You'll need to adapt the date format to what you want, check in the FormCalc reference.

Hope this gets you going in the right direction!

The code is on the exit event of a date field.

var endDate = Date2Num($,"YYYY-MM-DD")

var dayOfWeek = Num2Date(endDate, "E")

 

if (dayOfWeek <> 2) then

          xfa.host.messageBox("Start date must be a Monday")

          $ = null

          xfa.host.setFocus("$")

endif

Pg1.subTableReg.Table2.Row1[6].Date = Num2Date(endDate + 6, "DD")

Pg1.subTableReg.Table2.Row1[5].Date = Num2Date(endDate + 5, "DD")

Pg1.subTableReg.Table2.Row1[4].Date = Num2Date(endDate + 4, "DD")

Pg1.subTableReg.Table2.Row1[3].Date = Num2Date(endDate + 3, "DD")

Pg1.subTableReg.Table2.Row1[2].Date = Num2Date(endDate + 2, "DD")

Pg1.subTableReg.Table2.Row1[1].Date = Num2Date(endDate + 1, "DD")

Pg1.subTableReg.Table2.Row1[0].Date = Num2Date(endDate + 0, "DD")

Pg1.subTableReg.Table1.Row1[6].Date = Num2Date(endDate + 13, "DD")

Pg1.subTableReg.Table1.Row1[5].Date = Num2Date(endDate + 12, "DD")

Pg1.subTableReg.Table1.Row1[4].Date = Num2Date(endDate + 11, "DD")

Pg1.subTableReg.Table1.Row1[3].Date = Num2Date(endDate + 10, "DD")

Pg1.subTableReg.Table1.Row1[2].Date = Num2Date(endDate + 9, "DD")

Pg1.subTableReg.Table1.Row1[1].Date = Num2Date(endDate + 8, "DD")

Pg1.subTableReg.Table1.Row1[0].Date = Num2Date(endDate + 7, "DD")

I originally tried to get this working with a loop, but couldn't seem to get it to work.

Avatar

Level 3

This is definately a big help and on the right track. However I am having issues with the focus. If i choose NOT a monday i get stuck in a sort of loop with the message.

I will keep trying to fix this, but my other option would be to create a dropdown box that is populated by all mondays for the current year. Anyone have any suggestions on that?

Avatar

Correct answer by
Level 10

Just comment out the xfa.host.setFocus("$") line - you'll still get the popup and the field will be set to null.

But the whole point is to make the person pick a Monday, and if you need the date before anything else happens using the setFocus command is a good method. So yes, you can sort-of get stuck in a loop, but it's easy to get out of the loop by following the instructions and selecting a Monday.

Populating a dropdown box with all Mondays would be more of a pain for the person filling in the form I think - it's going to be a big dropdown list.

Avatar

Level 7

Hi,

Just to make sure you understand and there is no confusion, make sure you are using Jono's advice for using FormCalc instead of JavaScript. I find FormCalc is much more forgiving navigating the SOM and has really nice built in functions for date calculations. So, Jono is giving excellent advice.

I noticed there may be some confusion, because one of your other questions in this forum seems to mix the two languages. Also, dropdown boxes don't behave the way you might expect--so read-up on them. You will spend a lot of time struggling to harness them if you don't understand how they work. It is not intuitive.

Stephen