Skip navigation
ksumwalt
Currently Being Moderated

Circle day abbreviation

Jun 26, 2012 5:55 AM

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?

 
Replies
  • Currently Being Moderated
    Jun 26, 2012 11:02 AM   in reply to ksumwalt

    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.

    var TodaysDate = Date2Num(DateField.formattedValue, "MM/DD/YYYY")

     

    You can wrap function into each other.

    To get the weekday number you can use.

    var Weekday = Num2Date( Date2Num(DateField.formattedValue, "MM/DD/YYYY"), "e")

     

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

    var Weekday = Num2Date(Date2Num($.formattedValue, "DD.MM.YYYY"), "e")

    for i = 0 upto 6 do

              if (i eq Weekday - 1) then

                        TextDay[i].border.edge.color.value = "255,0,0"

              else

                        TextDay[i].border.edge.color.value = "0,0,0"

              endif

    endfor

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 26, 2012 1:11 PM   in reply to ksumwalt

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 27, 2012 10:14 PM   in reply to ksumwalt

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

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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points