Skip to main content
Participating Frequently
May 13, 2024
Question

Spawn a template, or hide a page?

  • May 13, 2024
  • 2 replies
  • 476 views

I am trying to do two things here. Part 1 works, but the spawning piece is off. Help, please, and thank you.

 

I have created the template and it is hidden.

 

//enters full name of child when child is 12 or over//

//spawns new page CARITemplate when child is 12 or over//

//otherwise blank//

 

var child = this.getField("ChildAge").value;
var childFirst = this.getField("ChildFirstName").valueAsString;
var childMiddle = this.getField("ChildMiddleName").valueAsString;
var childLast = this.getField("ChildLastName").valueAsString;

 

if (child < 12) {event.value = ""};
else {event.value = childFirst + " " + childMiddle + " " + childLast;}

AND this.getTemplate("CARITemplate").spawn(this.numPages, false, false);

 

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
May 13, 2024

Is this a calculation script? If so, it's not going to work correctly. It will spawn a new page each time you change the value of any field in the file...

Participating Frequently
May 13, 2024

It is a calculation script for a text field that only populates when the child is 12 or above.

 

If it is impossible to do this, would it work to hide the page if the child is less than 12? How do I name the page? Keep it as a template and reference it? Or just go by the page number?

 

try67
Community Expert
Community Expert
May 13, 2024

You need to use an event that is only triggered when the age is changed, such as the Validation script of the "ChildAge" field. Deleting the additional page should be done there as well, based on the number of pages in the file.

Participating Frequently
May 13, 2024

I forgot to add my other thoughts. I could delete the template and keep it as a page. Then I could hide the page if the child is less than 12, but am unsure of the syntax. Since I am already testing for age I think it makes sense to keep it all together.