Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Circle day abbreviation

ksumwalt
Level 3
Level 3

Hello all.

When using a Date/Time Field, how do I change the field's value to an actual Date variable?  I have tried

var d=new Date(reportDate.rawValue);

but it does not seem to work.

Long versions:

I have a form that has a Date/Time Field that is set to a Date format.  Under it I have 7 text elements, each representing a day of the week:  M  T  W  TH F  S  SU  Each text element has the same name:

TextDay[0] = "SU"

TextDay[1] = "M"

etc. to

TextDay[6] = "S"

I have set the Border to each TextDay to display as a circle around the text element, and want to show the border only for the day of the week associated with the date.  Unfortunatley I can't ge the border to show, and it seems this is because the value of the Date/Time Field is just text.  Here is what I have tried using:

var d = new Date(reportDate.rawValue);

var reportDay = d.getDay();

for (var i=0; i<7; i++)

          {

          if (i == reportDay)

                    {

                    xfa.resolveNode("TextDay[" + i + "]").border.presence = "Visible";

                    }

          else

                    {

                    xfa.resolveNode("TextDay[" + i + "]").borderStyle = "none";

                    }

          }

I have tried both the border.presence and borderStyle as shown above, but also placed the value or reportDay in a text field, which was placed as "Empty"

Any idea what I need to do to get the reportDate as an actual Date object so I can use the value?

0 Replies
radzmar
Level 10
Level 10

Hi,

internal a date is nothing else than a counter started from a date back in history.

Today is 41085 for example.

But in forms dates are formatted in manifold ways, so it's hard to resolve that counter from a user input.

With XFA forms you can, no! you should use FormCalc for date calculation.

This programming language is not that complex as JavaScript but it has more powerful date (Date2Num/Num2Date) and time (Time2Num/Num2Time) functions.

To resolve todays counter from a date field you can use.

You can wrap function into each other.

To get the weekday number you can use.

Here an idea for your form to hinghlight the textfield of the selected weekday.

ksumwalt
Level 3
Level 3

radzmar,

Thank you for the reply.  It looks like your code is in FromCalc and not JavaScript.

I have managed to figure out the date part since posting.  I need to use formattedValue and not rawValue:

     var d = new Date(reportDate.formattedValue);
     var reportDay = d.getDay();

I do still need to force the border.  I have found that I can put a border around each text item and  turn the "presence" to "visible" or "hidden", but this does not hold.  When I save and then re-open the form, it shows all the borders.  I have renamed each text field, also, to TextDay1, TextDay2, etc:

for (var i=0; i<7; i++)

          {

          if (i == reportDay)

                    {

                    xfa.resolveNode("Page1.TextDay" + i).border.presence = "visible";

                    }

          else

                    {

                    xfa.resolveNode("Page1.TextDay" + i + ".border").presence = "hidden";

                    }

          }

I am still trying to figure out how to set the border's edges.  I have seen references to .ui.oneofChild, but I am not getting the syntax right, or something else is wrong.

I may end up putting circle elements on to pof the text elements and unhiding the appropriate one, but using the border seems more eligant and uses fewer elemts, plus i only have to move 1 item instead of 2.

radzmar
Level 10
Level 10

Hi,

so you script seems to work, but the changes aren't recovered when reopening the form, right?

This behavior is propably because the setting to preserve script changes is no set to automatic in the form properies.

Goto File > Form Properties > Default > Preserve Script Changes and set it to Automatic.

ksumwalt
Level 3
Level 3

Thank you, radzmar. That was the problem.

Now the only issue is that the date and script changes are only preserved if another field is filled in before saving the form.  Oddly, it seems the other field can be filled in before or after filling in the Date/Time field.  Setting a hidden in the same script does not solve the problem.  Note that the script is being run in the reportDate::exit event.

radzmar
Level 10
Level 10

Hmm, I don't know what's the reason.

Can you share your form on Acrobat.com or so?