Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

Check for empty table row before adding date

Avatar

Level 9

On the form below, when I click the green + button (far right), a new table row is created with today's date. the user can then enter more text to the right of the date. Problem is when the form is saved and reopened, the text the user enters is deleted and new today's date added because it is in the intialize event. How do I script to check and make sure each dated row is empty before adding today's date?

https://acrobat.com/#d=qTINfyoXA-U6cDxOGgcSEw

Thanks,

~Don

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Don,

One option would be to use the caption area of the textfield for the date and leave the value portion free for the user to input their data:

if (xfa.resolveNode("this.caption.value.#text").value === "") {

          this.caption.value.text = util.printd("[mm/dd/yy] ", new Date() );

}

See here: https://acrobat.com/#d=VjJ-YsXLKmV6QU84JrAAIw.

Hope that helps,

Niall

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

Hi Don,

One option would be to use the caption area of the textfield for the date and leave the value portion free for the user to input their data:

if (xfa.resolveNode("this.caption.value.#text").value === "") {

          this.caption.value.text = util.printd("[mm/dd/yy] ", new Date() );

}

See here: https://acrobat.com/#d=VjJ-YsXLKmV6QU84JrAAIw.

Hope that helps,

Niall

Avatar

Level 9

Niall,

Your solution works great!

Is it also possible to use a text field to the left of this text field (in subform) so I can have the option of allowing the user to be able to change the date?

Thanks again!

~Don

Avatar

Level 10

Hi Don,

Yes it would. You would just need to reference the textfield. Maybe get the script to populate the textfield on the button's click event rather than the textfield's initalize event. That way it will not get overridden when the form is reopened.

Niall

Avatar

Level 9

Thanks for your help with this Niall.

~Don