Expand my Community achievements bar.

SOLVED

Creating mandatory field when form is visible only

Avatar

Level 1

Hi,

I'm creating a form that has around 25 pages inside it. The main page has a dropdown list which allows the user to select one of the 25 pages and once selected the specific page goes from hidden to visible. (They are originally all hidden). Each of the 25 pages contains radio buttons and I want to make them mandatory fields when the page they are on is visible and not hidden. How do I do this? I searched through the forums but I could not find a step by step set of instructions for those that are not very tech-savvy with LiveCycle. Is there an action builder function I can use? if not, what script do I need and where/how do I enter it? I am inexperienced with script and would appreciate lamens terms.

Thanks in advanced

1 Accepted Solution

Avatar

Correct answer by
Level 7

there are a few ways to do it depending on how you have set the form up. You could put the code in the exit event of the dropdown list or in the layoutReady event of the radio buttons. The logic is the same - basically you use the "presence" (whether it is visible or hidden) to decide whether the "nullTest" is on or not (this makes it mandatory - "error" is on).

So for example you culd put this code in the radiobuttons in the layout event (in FormCalc):

if (Subform1.presence == "visible") then

$.validate.nullTest = "error"

else $.validate.nullTest = "disabled"

endif

View solution in original post

8 Replies

Avatar

Correct answer by
Level 7

there are a few ways to do it depending on how you have set the form up. You could put the code in the exit event of the dropdown list or in the layoutReady event of the radio buttons. The logic is the same - basically you use the "presence" (whether it is visible or hidden) to decide whether the "nullTest" is on or not (this makes it mandatory - "error" is on).

So for example you culd put this code in the radiobuttons in the layout event (in FormCalc):

if (Subform1.presence == "visible") then

$.validate.nullTest = "error"

else $.validate.nullTest = "disabled"

endif

Avatar

Level 1

Can you provide me step by step instructions for the example you provided?

Can you clarify what a ready or exit event is and how to pull it up?

Where is formcalc? Do I select the radio buttons and then pull up formcalc, and then put in the code you listed?

Thanks for the reply!

Avatar

Level 7

Well the exact code will depend on what you have called your pages (subforms) but to do the above make sure you have the script editor showing (under the Window menu - or Ctrl + Shift + F5 on a PC). FormCalc is the language (there is a dropdown on the right side of the script editor). On the left side there is a dropdown called Show which has all the 'events' in it.

So to put that code in choose one of the radiobuttons from your hierarchy and choose the layoutReady event. Make sure the language is Formcalc and then copy and paste the code from above. Just change the name 'Subform1' to whatever you have called your pages.

Avatar

Level 1

Thank you for the instructions. I followed them and it was working for the first few forms but then whenever I enter the code for the radio buttons on page 5506 it gives me an error message every time I preview the form. Unfortunately I cannot post a picture on a forum from work but I will post it when I get home. I'll type out the error message for now and will post pictures when I can today.

Script failed (language is formcalc; context is

xfa[0].form[0].form1[0].page5506[0].#subform[0].validentryanswer[0])

script=if (page5506.presence == "visible") then

S.validate.nullTest = "error"

else S.validate.nullTest= "disabled"

endif

Error: accessor 'Page5506.presence' is unknown.

Script failed (language is formcalc; context is

xfa[0].form[0].form1[0].page5506[0].#subform[0]invalidentryanswer[0])

script=if (Page5506.presence == "visible") then

S.validate.nullTest = 'error'

else S.validate.nullTest = "disabled"

endif

Error:

Error: accessor 'Page5506.presence' is unknown.

Script failed (language is formcalc; context is

xfa[0].form[0].form1[0].page5506[0].#subform[0]invalidentryanswer[1])

script=if (Page5506.presence == "visible") then

S.validate.nullTest = 'error'

else S.validate.nullTest = "disabled"

endif

Error: accessor 'Page5506.presence' is unknown.

Message limit exceeded. Remaining 7 errors not reported.

Thanks for your all help so far, would appreciate your help on this

Avatar

Level 7

it looks like you have written 'Page5506' with a capital 'p'. It is case sensitive so try putting it back to a lowercase letter.

Avatar

Level 1

Ok I'll try your idea at work tomorrow (but I recall using capital letters for the other forms hmmm). In case that doesn't work, I wonder what else could be the problem... Here is a picture of my process and the error message that pops up in preview:

Entering in script.PNGerror2.PNG

Avatar

Level 7

you can see from the error message that your subform is called page5506 with a small 'p' but you have used a 'P' in the code

Avatar

Level 10

The best logic to use is the following exemple in the PDF...

https://drive.google.com/file/d/0Bz8yb5apn8y4a1RUY1R0R0RSbWs/edit?usp=sharing

It validate the whole form with exceptions fields if you need some

The script object validates every fields that are visible, and returns the name of the field that returns null to setFocus() on it.

Try it! better than Adobe LiveCycle validation itself