Expand my Community achievements bar.

Value in a Script Object

Avatar

Level 5

I created a function inside a Script object to convert a date e.g. 08-21-2003 to August 21, 2003. However I am hitting a wall on a very simple issue. How do I get the value out of the script object? I know there is a very simple solution. I just don' t have it.

     In one text box you enter 08-21-2003 and on a click event of a button another text field shows August 21, 2003.

https://workspaces.acrobat.com/?d=rn6iiSqrBNb2BOChVUn26A

3 Replies

Avatar

Level 10

Pass the field to the function along with the value (you could pass the initial field as a variable too so the function is reusable):

prince.dateConverter(form1.Page1.Date.rawValue, fieldName)

Then in the function use a variable to hold the field:

function dateConverter(curdate, oField)

At the end of the function write the value to the field variable:

oField.rawValue = fullDate;

There is an easier way to accomplish what you are doing using Patterns though. You've used text fields but if you use date fields you could just send the rawValue of the first date field to the second one with the Display Pattern of the second field set to date.long{}.

Avatar

Level 5

Jono,

     Thank you for your help. I agree there is an easier way. One would think this would be an easy validation pattern to perform. However the validation of fields via the tabs "Display", "Edit".... never seem to work for me. This linked form is a case in point. I have attached the form working for the script object. But nothing I do gets the date{long} format to work in the textfield with the caption "B". Let me know if you can figure out why. It would be nice in the future to use these validators.

    I had to create a new textfield to get the the value in the August 21, 2003 format. I don' t understand why textfield (named "A" or "Converted Date") doesn't take the function oField value but "NewField" will.

Greg

https://workspaces.acrobat.com/?d=tLu1yEu1f*FNJYWH-V7sGg

Avatar

Level 10

You can't use a date display pattern on a text field, it has to be a date field.

The only way around that is to use scripting to format the date and then put the date in a text field - I've done this using util.printd() (I think - going off the top of my head at the moment) and there's a way to do it with FormCalc too.

Patterns work well once you get the hang of them. Display is how you want the data to look. Edit is the different ways you allow the data to be entered (multiple date, phone number patterns, etc.). Validate will validate that the Display pattern has succeeded. Data is the format to export.

I haven't had a chance to look at your new file but if you use 2 date fields with patterns you would just need: dateField2.rawValue = dateField1.rawValue; with dateField2 having date.long{} as the display pattern. Come to think of it you could use Global binding and give the fields the same name and you wouldn't have to do any scripting.

Radzmar has a good explanation of using multiple edit patterns for dates (English text is part way down): http://thelivecycle.blogspot.de/2011/10/date-patterns.html