Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

If Holiday Date Then Display Holiday Name In Another Field

Avatar

Level 3

I'm trying to make a form so if a Date&Time field is set to a holiday date i.e. 9/5/2011 or 12/25/2011 then another field would display the holiday name i.e. Labor Day or Chrismas Day.

Thanks for the help.

14 Replies

Avatar

Former Community Member

I found this function on the web that will check for American holidays. I had to modify to suit our needs but it shoudl give you the idea. Have a look at the function to add or remove the dates that you do not need or want. I didn't check all of the holidays so check it out and try it over a couple of years.

Paul

Avatar

Level 6

Here's another solution that will work for you:

if (xfa.event.newText=="9/5/11")
{holiday.rawValue="Labor Day"
}

java script on a "change" event of the date field

holiday is the name of the text field

Avatar

Former Community Member

I thought of that solution but you woudl have to update the form each year to reflect the new dates for each holiday.

But yes that woudl work and is simpler also.

Paul

Avatar

Former Community Member

All the magic code is in the script object (MyScriptObject) in the hierarchy view. Simply click on that object and the code will appear in the script editor window. It is commented so you shoudl be able to follow it.

Paul

Avatar

Level 3

Is this what you are referring to?  This is all i see in the script editor and don't understand how to edit it,

form1.Page1.DateTimeField1::exit - (JavaScript, client)

app.alert(this.formattedValue)

TextField1.rawValue

= MyScriptObject.check_holiday(this.formattedValue)

Thanks.

Avatar

Level 3

How do i get it in a form i've already designed?

Avatar

Former Community Member

Highlight the scriptobject in the hierarchy view so that all of the script is in teh script window. Copy all of that script to the clipboard. Now open your form. Click on the 1st page subform and right click. Choose the Insert ScriptObject option. A new untitled ScriptObject will appear. Highlight that and give it a meaningful name (in my case a chose MyScriptObject). Now in the script window paste the code into the script object.

When you call the script object from your form you would use the name of your scriptObject.functionname(passing any parameters that the function calls for)

Hope that helps

Paul

Avatar

Level 3

So I got things almost working. Well, things are working but I’m getting some errors.

I have a seven page form with two fields on each page, a date/time field and a text field where the holiday will display if there is on that particular day. Each page represents a day starting on day one with the ability to select a date for day one and the rest of the days will fill in with the corresponding date and holiday if there is on that particular day.

I have the script that generates the holiday in the validate area opposed to the exit area because day 2 – 7 date/time fields have a calculated script which determines the date so those fields are not exited. When the form is opened and then when dates are entered it gives an Adobe Reader error which states the field name followed by validate failed, i.e. Day2 validate failed. However, there is an ok button and if clicked it validates the field.

This is done on 6 fields so the ok button has to be clicked 6 times when the form is opened and 6 more times once a date is entered. Anyway users wouldn't have to click ok 12 times?

Thanks!

Avatar

Level 3

Just to further elaborate here is the error message when the form is opened and when a date is entered in the StartDate field on the first page,

Here is script on the Day2 field as well as the rest of the Day fields throughout the form which seems to be causing the error. The + 1 changes to calculate the correct date from the StartDate.

form1.#subform[1].Day2::calculate - (FormCalc, client)

if (StartDate.rawValue==null) then

$.rawValue = ""

else

Num2Date(Date2Num(StartDate.formattedValue, DateFmt(4)) + 1, DateFmt(4))

endif

form1.#subform[1].Day2::validate - (JavaScript, client)

Holiday2.rawValue = MyScriptObject.check_holiday(this.formattedValue)

Thanks again.

Avatar

Former Community Member

Why did you put the code on the validate event .....woudln't it make more sense to put it on the exit event of the date fields so that the user knows immeadiately when they choose the date that they have chosen a date that is a holiday? Then you coudl give then the option of adding a day or choosing a new date.

Or am I missing something.

Maybe you shodul describe the action that you want to have happen and we can suggest the way to do it instead.

Paul

Avatar

Level 3

What I want is to enter a date in a date/time field and if there is a holiday I want it to display in another field on the same page.  However, there are 7 pages to the form and each page has a date/time field and a field to display the holiday.  On pages 2 – 7 the date/time fields is calculated from the StartDate on page one.

The way it works is if the StartDate is say tomorrows date Wednesday August 31st, 2011 the next page will display Thursday September 1st, 2011 and the next page Friday September 2nd 2011 and so on.  If a holiday is on one of those dates it will appear below the date/time field.  If there is no holiday nothing appears.

I have it on the exit of the StartDate field on the first page but will not work if I have it on the exit of date/time fields on the other pages I’m assuming because these are calculated.  So I put it in the validate area which works but throws up the error for each field.  See my post above for the error. 

I wish there was a way to upload the form.

Avatar

Former Community Member

Send the form to

LiveCycle8@gmail.com and I will have a look. Include a link back to this thread so I have a reference.

paul