Copy link to clipboard
Copied
Hi all,
I need to figure out a way of checking for a hidden text field on a spawned page and if that field isn't found then spawn that page.
So far i have this:
var f = this.getField("Page text 5.1").page;
var v = this.getField("Section 4").page;
if (f !== true){
this.spawnPageFromTemplate({
cTemplate: "Page5",
nPage: v+2,
bOverlay: false,
bRename: false
});}
Any help will be greatly appreciated.
Steve
Copy link to clipboard
Copied
The name of the field is "Page text 5", not "Page text 5.1". Adjust the code accordingly and it will work.
Same goes for "Page text 6.1", etc.
Copy link to clipboard
Copied
Before the page is spawned, the page property of that field will return a number (-1). Afterwards it will return an array, with one of the values being-1 and the other being the page number to which you spawned it.
So you can check the type of the object returned by the page property. If it's "number" it means the page hasn't been spawned (if you want to double-check that the template page is hidden you can check it's -1); If it's an "object" (meaning an array), that means there are multiple copies if it, and the page has been spawned.
This is all assuming this field only exists one, and on the Template page only, of course.
Copy link to clipboard
Copied
Thanks for your answer, so how do I search for an object as opposed to a number?
Copy link to clipboard
Copied
You can use something like this:
if (typeof this.getField("Page text 5.1").page=="number") {
// The template page HAS NOT been spawned
} else {
// The template page HAS been spawned
}
Copy link to clipboard
Copied
Hi Try67,
Thanks for your help but doesn't seem to work either.
Kind regards,
Steve
Copy link to clipboard
Copied
It should. Share the file for further help.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The name of the field is "Page text 5", not "Page text 5.1". Adjust the code accordingly and it will work.
Same goes for "Page text 6.1", etc.
Copy link to clipboard
Copied
Brilliant, Many thanks for all your help.
Copy link to clipboard
Copied
Check if field is not null:
var f = this.getField("Page text 5.1");
if(f !== null){
//rest of your script
Copy link to clipboard
Copied
That won't work. If the field exists on a hidden Template page it will not return null.
Copy link to clipboard
Copied
You are right, I thought he wanted the other way around.
Copy link to clipboard
Copied
It would work, but just check for null not !null, if he doesn't have other copies of the same field.
Copy link to clipboard
Copied
It will not work. The field will never be null.
Copy link to clipboard
Copied
Thanks Nesa,
But Try67 is correct, it's not working.
Copy link to clipboard
Copied
You can spawn a template page and then check if field exist on that page, and if it does exist then delete that page otherwise leave the page spawned.
Copy link to clipboard
Copied
Hi Nesa,
The ideal scenario I would like to get to is to do a reset to all the spawned pages on all 4 button clicks. I have a script that will delete the spawned pages, using the form field name on the template, but that dies when it can't can't find a field name and the rest of the script doesn't work. I was going to to try If Else but that didn't work, I can't seem to find something that says if not present then ignore and move to next line (type of thing).
Many thnaks for your help so far. You've been amazing and have helped me no end