Copy link to clipboard
Copied
I have a form with two templates that are spawned as necessary (user generated) the first is named "tpt_Soil" and the second is "tpt_Veg". The entire form (with no additional pages added) is 11 pages. Sometimes the user will need additional copies of "tpt_Soil", sometimes not. Same with "tpt_Veg". Copies of the second one could start on page 12, but it also could start on page 15 or 16, depending on the scenario.
"tpt_Soil" has no calculations, so my button action javascript works no problem:
var SoilPage = this.getTemplate("tpt_Soil");
SoilPage.spawn(this.numPages, true, false)
However, "tpt_Veg" is more complicated, it is two pages long AND has a number of calculated fields. How do I rewrite the scripts for those fields so that they will still work in the spawned (and renamed) templates?
So for example on tpt_Veg there are fields named: F1a.Strata.Canopy, F1a.Strata.SubCanopy, F1a.Strata.Shrub, F1a.Strata.Herb and then F1a.Strata_Total which is the sum of the F1a.Strata fields.
Right now that's done through the pick-list calculations, but obviously won't work when the fields are renamed Pxx.F1a.Strata because I don't know what page they will end up as.
Names of fields in a spawned page are predictable. They are made out of the page number to which the page was spawned, the name of the template and the original name of the field. You can use this pattern to write a script that will perform these calculations, even when the fields are on spawned pages.
You don't need to, because it's the same page (presumably) as the one where the calculated field is on, so you can get that information from that field's name, which you can access using event.target.name .
Copy link to clipboard
Copied
Names of fields in a spawned page are predictable. They are made out of the page number to which the page was spawned, the name of the template and the original name of the field. You can use this pattern to write a script that will perform these calculations, even when the fields are on spawned pages.
Copy link to clipboard
Copied
What if I don't know what page it will be on?
Copy link to clipboard
Copied
You don't need to, because it's the same page (presumably) as the one where the calculated field is on, so you can get that information from that field's name, which you can access using event.target.name .
Copy link to clipboard
Copied
Can you give me an example?