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

Is this concept possible??

Avatar

Former Community Member
Is it possible to make a form where when the form loads user puts in personal info (like name etc) on page 1 and that page also has two radio buttons; depending on what option the user chooses, a new page opens up. That is if user clicks on RB1, page 2 opens ; if user chooses Rb2, Page 3 shows - with the personal info already filled in. (from the first page where user entered in the beginning)



Is it possible to implement this?



Thanks

Marleen
13 Replies

Avatar

Former Community Member
Sure it is!



Since the top-level form object ("form1" by default) is always a flowed subform, all pages have Instance Managers that you can use to add or remove instances of them.



By setting the page 2 and page 3 subforms as repeatable (check the
Repeat Subform for Each Data Item box on the Object palette's Binding tab) and having no initial instance (
Initial Count set to zero (0)), page 2 and page 3 won't exists at first. All you need after that is code on each radio button to either remove the instance of page 2, add an instance of page 3 and populate fields on page 3 with information on page 1 or vice-versa for the other radio button which adds an instance of page 2 to the form.



Here's an example of the kind of JavaScript you could use on a form which has a single "name" text field on all pages and populates this field on the page that's added to the form depending on which radio button the user picks (on a radio button's Click event):



// remove page 3 if it exists

if (form1._Page3Subform.count > 0)

form1._Page3Subform.setInstances(0);



// add page 2

form1._Page2Subform.addInstance(0);



// populate the name field on that page with the value of the name field on page 1 (this page)

form1.Page2Subform.P2Name.rawValue = P1Name.rawValue;


The attached form shows this code in action.



Stefan

Adobe Systems

Avatar

Former Community Member
Thanks a ton...this is neat..



But is it possible to remove Page 1 when the radio button is checked.



For example in your form, when user chooses RB1, page 2 shows but after page 1 and user has to scroll to page 2. What I need is that when user chooses RB1, page 1 disappears and page 2 shows instead. Similarly, when RB2 is clicked, page 3 shows and page 1 disappears. So the form will always show only one page.



Thanks

Avatar

Former Community Member
Well this one was tricky but I think I've got it now. I was trying to do something really complicated with the Instance Manager and it wasn't working very nicely (Acrobat was getting into this state where there was only one page but the page counter and page scroll bar were set for 4 pages... yikes!).



My solution: Place 2 subform on the one-and-only first page. Make them the same size as the page subform (8in x 10.5in by default) and name them Page1Subform and Page2Subform (or something else but let's use those names for reference here). On each subform, place the fields you want along with an instance of the radio button group. Let's say that the second radio button on Page1Subform is supposed to remove page 1 and show page 2. On this radio button's Click event, you would add script which makes Page1Subform invisible, sets the value of the radio button group on Page2Subform to the second radio button, transfers the values of all fields to mapping fields on Page2Subform and makes Page2Subform visible. You would then do the reverse on the first radio button on Page2Subform in order to hide Page2Subform, transfer the values to Page1Subform and show Page1Subform. Oh, and don't forget to set Page2Subform's initial visibility as "invisible" and set the default value of the radio button group on Page1Subform to the value of the first radio button so that the initial state of the form is correct.



This is
much simpler than what I was trying to do initially.



Check-out the scripts on the second radio button on Page1Subform and the first radio button on Page2Subform in the attached sample.



Stefan

Adobe Systems

Avatar

Former Community Member
This is amazing!! Thank you so much for such prompt response...This works great!!



This is exactly what i was looking for ; i have tons of controls to put on both the pages..so I am gonna try this with them. But I know this will work great..



Thanks so much once again!!

Avatar

Former Community Member
Ok..got stuck already!!



I want this code to execute on click of a button...so in click event of the button , I write if(RadioButtonList.rawValue==1){//code}



This does not make the 2nd subform visible..i have set the values same as yours(visible/invisible; position/flow etc)



my script is java script...but that should make any difference..should it??

Avatar

Former Community Member
I think you might be getting into timing issues with the events. I don't think the radio button list's value has been updated yet at the time you get the Click event notification on the radio button. But then, why bother checking for the value of the radio button group if you're putting this code on a radio button? Radio button groups are mutually-exclusive which means that the radio button that's clicked is the value that the radio button group will get so just setting the 2nd subform as visible and the first as invisible without checking the group's value should work just fine...



Stefan

Adobe Systems

Avatar

Former Community Member
I am not changing the values of radio buttons...since i do not need to show page 1 back once i show page 2..i didnt need that any ways..



I tried this with just a few controls: text box, radio buttons(2 ofcourse and a button) on page 1 and just a text box on page two.

page 1 is visible, page is not.



in click event of button, i write

if(RB.rawValue == 1){

form1.pg2SF.presence = "visible";

form1.pg1SF.presence = "invisible";

}

this does not execute. Just to check if the code is right..i wrote



if(RB.rawValue == 1){

app.alert("hello");

pg2SF.presence = "visible";

pg1SF.presence = "invisible";

}

It shows me a hello message on click of the button..but does not make pg2SF visible..Why is that??



FYI: I have LC designer 7.0 and reader 7.0.3...just in case that has something to do with it...

Avatar

Former Community Member
Are you certain you saved your form (or are previewing your form) as a
dynamic PDF? If it's saved (or being previewed) as a static PDF, you won't be able to change the presence of subforms dynamically.



If your form is already saved
as a PDF, then re-save it as a dynamic PDF file. If it's already saved as an XDP, then make sure that the XDP Preview Format property on the Form Properties dialogs Defaults tab is set to
Acrobat 7.0 Compatible Dynamic PDF. If it's not saved, then (you should probably save it! ;) ) make sure that the Default File Type for New Forms property in the Options dialog's Document Handling tab ("Tools | Options..." menu) is set to
Acrobat 7.0 Compatible Dynamic PDF.



Also, it sounds like you're letting the user pick a radio button and then having them click on a button object in order to show the proper page. If that's the case, then the script on the button object's Click event should be checking the radio button
group's value (as opposed to not having the check the value of the radio button when you place the script on the radio button itself). Which makes me wonder why you aren't using a single check box instead of a radio button group with two radio buttons if you aren't letting the user get back to page 1...



Stefan

Adobe Systems

Avatar

Former Community Member
My form is saved as a dynamic pdf...In Tool-->Options-->default is set to dynamic(I do not see acrobat 7.0 compatible dyanamic though)...



I was just trying your form with a Button..what i actually need in my form is 5 pages.



Page 1 would take user personal info and ask for two seperate questions:

Que 1. Are you a US employee or a non US employee? (So I thought i wud use RB)

Ques 2: Do you want to enter details/update details?(RB again)

Click on submit Button.



page2: US emp; enter details

page 3: US emp;update details

page 4 NON US; enter details

page 5: Non US; update details

also page 2-5 wud show user name from page 1.



depending on combination of Radio Buttons choosen, specific page(from 2-5) would show.



I am making so many pages because I have tons of controls to use and each page has different fields..i cannot re-use any sub form?



Do you think what I am planning is good????And can this be implemented??

Avatar

Former Community Member
I think it's an acceptable form design given that you have a lot of controls on each form. You might find it easier to place each "page" subform on their own pages while you design it and then move each "page" subform into the first (and only) page and make them all invisible except the initial one.



The fact that you don't let the user go back to the initial page makes things much simpler. Now, all you need to do is put code on the button which checks the values of each group of radio buttons and, if the selection is valid, shows the appropriate subform and hides the initial one. Also, you'll save yourself a whole of scripting if you make the fields shared amongst all pages (such as the Name field)
global. You do this by selecting
Global in the Default Binding property on the Object palette's Binding tab for each field. This means that all fields with the same name will have the same value (so typing the name in the initial page will automatically replicate it in all Name fields on all other pages without you having to do anything). Note that this also implies that if you export the XML data from the form, you'll get a single Name node as opposed to one per page.



I've attached a sample form which I think finally replicates what you're trying to do.



Stefan

Adobe Systems

Avatar

Former Community Member
Whoa...This is unbelievable!!!



This is exactly what I wanted to do [but had no Idea how?? :)]



Thank you so much once again...I really appreciate all your help and cant thank you enough...

Avatar

Former Community Member
You're welcome!



Sometimes it's certainly not obvious. Even I started by using the instance manager on the pages and discovered it was a bad idea (theoretically sound, I think, but not good for Acrobat). What's thrilling is figuring-out how to get it done -- and using the product I work on to do it!



Stefan

Adobe Systems

Avatar

Former Community Member
Continuing in the same flow as above..I have a form with 7 pages.

Only 6 pages show at the time of form load. Page 1 of the form has a check box, if that is checked page 7 shows up but page 1-6 are not visible any more.

Page 7 contains another check box, which if checked makes 1-6 visible and page 7 is invisible again.



removeInstance/setInstances doesnt work. Making it invisible doesnt work either.becaus I am still left with empty pages (Controls get removed)



Any input on how to do this?



Thanks