These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Test Radio Button Value and Set Check Boxes to Required

seiferlm
Registered: Mar 30 2011
Posts: 15

So the preface here is that I'm new to Adobe forms, specifically LifeCycle Designer (8). I do have some JS under my belt but it's rusty.
 
I need to evaluate a radio button's (group called rb) value (Yes or 1 is called rby and No or 0 is rbn) to determine what the user selected. If they select Yes, I need to set the property of 3 checkboxes to required (script1). Ideally, I'd like to take this a step further and gray out said checkboxes and un-gray them when the user chooses Yes (since the default is No). The user may tab through or mouse wherever they need to on the form so I "thought" that:
 
1. script1 should be written in the validate or exit event of the radio button but I tried doing this in both events for rb and rby and the script doesn't trigger (whether I tab through, mouse through or hit my submit button). See script below, which may be written incorrectly and therefore responsible for the script to fail.
 
2. A second script on my submit button's validate event could be used to make sure that the combination of the radio button's value of Yes and one of 3 checkboxes being checked off occurred before the form is submitted. A discussion to follow later.
 
I've tried a variety of tactics which all failed. So I'm hoping some kind soul can provide me with newbie step by step instructions as to where my JS should be written and a sample of code that demonstrates how I might accomplish the above.
 
This, at least, will point me where I'm supposed to go rather than what has so far been a very extensive trial by error process that has yielded no results.
 
This is the JS I tried for script1:
 
var RBt = this.getField("rb");
if (RBt.value == true)
{
app.alert("rb is Yes."); //to tell me if the test was triggered
var CBr = getField("CB1");
CB.required = true;
var CBr = getField("CB2");
CB.required = true;
var CBr = getField("CB3");
CB.required = true;
}
 
Any help?

MJS

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
"getField()" is a function in the AcroForm JavaScript model. Field properties in a LiveCycle form are accessed in a different way.

First, since this is for a radio button the script should be on the Click event. The radio button values should be 1 and 2. And there is no "required" property on LiveCycle form elements. Instead they use the "mandatory" property. So, the script should look something like this.

if(this.rawValue == 1)
{
CB1.mandatory = "error";
CB2.mandatory = "error";
CB3.mandatory = "error";
}

To learn about graying out fields see this article.
http://acrobatusers.com/tutorials/2007/09/js_disabling_fields


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

seiferlm
Registered: Mar 30 2011
Posts: 15
Thanks, Thom. Why is CB1.mandatory set to "error" vs true. Does this syntax mean that "error" is a standard value which functionally means an error should generate if not checked? Just trying to understand what this means in LifeCycle.


MJS

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
There is a history behind the syntax. The mandatory property was added in Acrobat 7 or 8, I don't remember. It is an abstraction of the null test for a field. The null test is the "required" test applied to each field before submission.

You need to download the "XML form object model" reference from the Adobe site. It's all in there.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

seiferlm
Registered: Mar 30 2011
Posts: 15
Okay so I had a couple of problems. My syntax was incorrect and, while I tried the click event at some point, the syntactical problems prevented the script from triggering. I am taking you literally though with respect to the correct syntax/reference of CBs. If my CB is called CB1 then your syntax should work? When I click on my submit button, ostensibly I should get an error saying CB1 is now required and it was not checked off, for example, because the above script should have made the CB required. But I don't get a pop up or any evidence of an error having occurred.

Also, I did take a look at your article previously but it was unclear to me where those functions should be written. Which object, which event. And from where are those functions being called? I assume, in my case, inside my click event from which I pass each of the three CBs.

MJS

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Just try putting this code in the Click event for the Radio Button Group. Make sure there are no other scripts in any event on either the individual buttons or the group. And make sure the language is set to "JavaScript"

app.alert("Selection=" + this.rawValue);

If this works then you've got the first part done. The next bit is to identify the correct SOM path for accessing the combo boxes. My script was written as an example since I don't know the exact hierarchy of your form.

Watch this video:
http://adobechats.adobe.acrobat.com/p87746471/






Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

seiferlm
Registered: Mar 30 2011
Posts: 15
I already had an alert in my script for precisely that reason. So the conditional statement is executing. But my syntax literally says CB1.mandatory = "error" for each CB. And I test whether this actually does anything for me (i.e. forces the user to check the box off before the form submits) by clicking on my submit button. But I don't get any errors back at that point. My hierarchy is:

form1
(Master Pages)
Page 1
(untitled Content Area)
myForm

with all objects under myForm (submit button, CBs, RBs, combo boxse, text boxes, images, etc.).

And my submit button is an Email Submit Button at this point although I have a series of other issues/questions to be addressed at some point(saving to PDF, being able to save the PDF to local drive and dynamically constructing the name of the PDF all in one click of a button). This issue spun off a whole other set of questions, problems, researching answers, trial and error efforts.

So I'm trying to pick off my questions one by one. First I want to be able to get data validation working on my form. I had hoped to be able to just write a bunch of JS in a form submit type of event for all validation necessary on the form then be able to intercept any action to then submit the form if an error occurred (much like you would on a web page which I have written plenty of).

Anyway, for simplicity, all objects are one level down from myForm. There are, of course, RB groups and a couple of CB groups but other than that, no sub forms below that. So my submit button, RB and CBs are all hierarchically at the same level. If that helps.

I am currently trying to keep up with this post and watch your video at the same time.

But based on your last comment, should my check box reference be xfa[0].form1[0].myForm[0].CB1.mandatory = "error"? That doesn't seem logical to me in light of how the reference to the RB is written. But I am a newbie.

MJS

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
So are you saying that you put the form fields in a Master Page? Probably not a good idea, but if they are all in the same subform, then they are all on the same hierarchy level and can be accessed directly using the field name. The next step then is to make sure you can access the comboboxes. Put this line in your script

app.alert("Combo#1 = " + CB1.rawValue);


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

seiferlm
Registered: Mar 30 2011
Posts: 15
Sorry, I showed indenting when I provided my hierarchy which was lost when I saved my post. It is:

form1
-->(Master Pages)
---->Page 1
------>(untitled Content Area)
-->myFormIn any event, an app alert referencing CB1 using your syntax does produce an alert message. So maybe I'm misunderstanding how the CB1.mandatory property works as it relates to a submit?

MJS

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Setting "mandatory" to "error" turns on the null test, which does exactly that, it tests the field for a null value, or in the case of a text box, an empty string. Does the combobox contain anything. Check the value by running this code in the console window.

":" + xfa.form.form1.myForm.CB1.rawValue + ":"

If something is displayed in between the colons then the value isn't null. Even if it's a space.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

seiferlm
Registered: Mar 30 2011
Posts: 15
When I added the app alert the value that returned was 0 since the check box is turned off by default. So it can be referenced. It's just that setting the mandatory property doesn't appear to cause any effects when I submit.

MJS

seiferlm
Registered: Mar 30 2011
Posts: 15
I am heading back to where I'm originally from in a few minutes so I'll be off line until tomorrow/Friday. But I do appreciate you helping me walk through this since there a number of fundamental issues I need to work through as I have a bunch of forms I need to develop all for the same company with fundamentally the same layout and similar issues (conditional error checking, hiding/displaying dependent objects, general syntax issues, etc.). So I need to work through all of those before I use my current form as a working form for subsequent forms.

Hopefully, I'll be able to pick up with you over the next few days while I try to work through issues. I've developed the kind of forms I need from Adobe for web sites. But I'm just struggling with LifeCycle Designer itself as I mentioned. I watched your video which covered much of the basics I had already worked through although there were a couple of pieces of information (saving a form as dynamic) which I didn't know about and will be helpful.

Are there any gotchas I need to be concerned with in purchasing a copy of LifeCycle Designer for working at home? I haven't been able to find v8 for a reasonable price anywhere but did find v9. I'm just concerned about running into development issues between versions. Anything you might be aware of about this that I should watch for would be helpful (and potentially prevent some headache that I don't want to deal with right now).

Thanks again and signing off...

MJS

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Ahh, I misunderstood something. For some reason I was thinking the "CB" elements were comboboxes, but they are check boxes? I missed that in the first post. You want to make the form choke if the checks are not checked?

Checkboxes are not part of the standard set of fields that can be required. After all, they always have a value, either on or off. You can see this in LiveCycle Designer on the Object->Value tab. Text boxes have a selection for required, but checkboxes do not.However, you can still use the null test on a check box. I just tried a quick test from the console window. The code I provided should work if the field names are correct.

In fact, run this code from the console window.

xfa.form.form1.myForm.CB1.mandatory

It will tell you the current state of the null test for the check boxes. By default it should be "disabled".


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

seiferlm
Registered: Mar 30 2011
Posts: 15
I'm back. Well ideally I'd want to make the check boxes disabled until the click event of a radio button produces a particular selection. Once that selection is is made, then I'd want the check boxes to be enabled and when the user submits the form, I'd want to validate that at least one of those check boxes are checked off (if the particular RB selection was chosen). So

RB1 (No) RB2 (Yes) CB1 On/Off CB2 On/Off CB3 On/Off

If RB2 is selected (RB is the radio button name for eg) then CB1 through CB3 need to be enabled or hidden then shown or grayed out then ungrayed out or at least some property set so that it can be evaluated on submit to ensure something is checked when RB2 is selected.

Or do you have a simpler solution than all of the above?

MJS

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
When a check box is given a null test it will fail if the check box is unselected. The null test only works for simple single value testing. If you want something more complex, such as at least one check box is set, then you have to write a script to do the checking. Forget about setting mandatory.

See the articles on this site that cover form submission and validation. I think there are some examples of custom validation scripts.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

seiferlm
Registered: Mar 30 2011
Posts: 15
Can you tell me precisely where I would write a script to validate various objects on my form upon submit (in order to allow for failure and stopping the submit or email to process? Do I click on my form then choose the preSave event (then have to repeat the validations on prePrint)?

I'd like to be able to cycle through all objects for which I want to do some validation and set a validation flag to false then test it at the end to either continue with the save/print or stop. Can I do this and where (as in which object/event)?

MJS

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Do a search on this site for "Submit Validation"

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

seiferlm
Registered: Mar 30 2011
Posts: 15
I'm seeing references to objects and functions but not finding exactly what I'm looking for. For instance, there was a reference to LifeCycle Designer (LD) submit button and the mouse down event being what I was looking for. I assume this means create a regular button of control type submit then write JS in the mouse down event. I did a simple test:

var tValidate = true;

if(field.rawValue != "")
{
if(relatedfield.rawValue == "")
{
app.alert("Specify a value.");
tValidate = false;
}
}
if (tValidate == false) app.alert("Validation failed so do not allow submit.");

but when field was provided a value but relatedfield was not, no error occurred. I moved this same script to an email submit button, again on the mouse down event. But no script triggers.

I tried isEmpty(form1.myform.field) and isEmpty(form1.myform.relatedfield) to no avail.

Is there somewhere where I can post the question:

I need to validate data in some fields on a form prior to allowing a submit to complete. What type of object should the JS be written into and which event?

where I can get a quick answer? I am under a time constraint and this question is holding me back from proceeding any further. Getting the syntax right for the JS is one thing but I can't even tell "where" to put it in the first place to get it to trigger. And I need one place that I can just write a string of JS doing various checks against different fields (in some cases checks dependent on other fields and in some cases fields that may get filled in in a different order than the form is actually organized thereby eliminating the ability to check when field loses focus since that may be okay until the form is actually finalized and ready to submit).

MJS