Making Checkboxes Required

960 views
Skip to first unread message

Mark.Veyette

unread,
Feb 6, 2008, 5:07:26 PM2/6/08
to Adobe LiveCycle Developers
I have a set of about 43 checkboxes. I want to know if there is a way
to make it required that at least one of them has to be checked, but
the user could also check more then one.

fred.pantalone

unread,
Feb 7, 2008, 10:58:15 AM2/7/08
to Adobe LiveCycle Developers
You'll have to code some JavaScript to accomplish this. If I were
implementing this I would probably use a hidden field to keep a count
of the number of "checked" checkboxes. Increment the value of the
hidden field whenever one of your checkboxes gets checked, decrement
when a checkbox is un-checked. When you need to ensure that at least
one is checked the test is simply (hidden field value > 0).

Another approach (which could be more of an maintenance hassle) would
be to check the value of each box at the time you need to do the test.

Fred

Mark.Veyette

unread,
Feb 8, 2008, 4:04:44 PM2/8/08
to Adobe LiveCycle Developers
Ya, thats exactly what I was trying to do. I have basic Java and C++
skills, but I've never worked with JavaScript, and this is my first
time using LiveCycle, so I'm kind of lost with were to code what and
how "exactly" to write it. Just searching for information I found a
bit of help, this is what I have so far. Its written for a hidden
numeric box that I have set to User Entered - Required and the default
is set to 0. But it doesn't work.

----- topmostSubform.Page1.CheckboxCounter::calculate: - (JavaScript,
client) ----------------------

this.rawValue = Materials[0].rawValue + Materials[1].rawValue +
Materials[2].rawValue.......ect.



----- topmostSubform.Page1.CheckboxCounter::prePrint - (JavaScript,
client) ------------------------

if (this.rawValue == 0)
{
this.mandatory='error';
}

fred.pantalone

unread,
Feb 10, 2008, 8:58:12 PM2/10/08
to Adobe LiveCycle Developers
Hi Mark,

What behaviour are you expecting exactly? I wouldn't use this approach
myself, making a hidden field mandatory. You should write your own
code on the preprint event. This code checks the value of your counter
field and use the xfa.host.messageBox() function to show an error.

Fred

Mark.Veyette

unread,
Feb 11, 2008, 5:38:44 PM2/11/08
to Adobe LiveCycle Developers
What I want to happen is that if no checkboxes are marked, it won't
print and the user will receive an error message.

fred.pantalone

unread,
Feb 12, 2008, 10:16:16 AM2/12/08
to Adobe LiveCycle Developers
Hi Mark,

You cannot cancel printing through scripting once "File/Print..." has
been selected by the user. What you can do is add a "Print" button to
your form (make it "visible - screen only") and instruct the user to
print via that button only. When this button is pressed you can
perform the required field checking and either report an error or
cause printing to occur via JavaScript. This is a perfectly acceptable
approach and is used quite often.

There are ways to hide the Print... item from the File menu and the
print icon but that's probably going too far.

I hope this helps...

Fred

Justin Klei

unread,
Feb 26, 2008, 4:43:35 PM2/26/08
to Adobe LiveCycle Developers
Here is how I typically handle the checkbox requirement. Suppose I
have 3 fields (A, B, C) and I want at least one of them to be
required. What I'll do is define a hidden text field, and on the
calculate event for that field I'll put the following script:
A.rawValue + B.rawValue + C.rawValue;

Then, the value of this field will always contain the number of
checkboxes that were checked. You can then use any mechanism you
would like to validate the value of this field and make sure it's
greater than zero.

It looks like you were going down the right path Mark, but I would
have made the CheckboxCounter a read only, calculated field. Also,
you had the following in your code:
.............Materials[0].rawValue............
You can't use the bracket notation in Javascript. One other thing I
would do if I were you is set the 'mandatory' property of each of the
checkboxes in your validation code instead of setting it on the hidden
field. That way the checkboxes are highlighted in red when you try to
submit the form.

As others have mentioned, there is no way to prevent printing of the
form. However, you could use the prePrint and postPrint events to
hide/show the page or individual fields when they try to print.

Hope this helps!

Justin Klei
Cardinal Solutions

José Soto

unread,
Mar 13, 2008, 7:13:55 PM3/13/08
to Adobe LiveCycle Developers
Hello.

I was reading what Fred posted before and I´m having some trouble
trying to hide the print item from the file menu and the print icon.
You said you probably know how to do this... Could you give me some
help on this???

Thanks a lot.

fred.pantalone

unread,
Mar 14, 2008, 10:59:02 AM3/14/08
to Adobe LiveCycle Developers
Here are some resources:

Look for hideMenuItem and/or hideToolbarButton in the docs available
here:

http://www.adobe.com/devnet/acrobat/javascript.html

In particular, look at the doc entitled "Acrobat JavaScript Scripting
Guide" and "Acrobat JavaScript Scripting Reference".

Here is some more information:

http://blog.stealthpuppy.com/deployment/deploying-adobe-reader-81

I hope this helps,
Fred

José Soto

unread,
Apr 4, 2008, 10:55:40 AM4/4/08
to Adobe LiveCycle Developers
Hello Fred.

Thanks a lot for your help. Really appreciate it!

On Mar 14, 9:59 am, "fred.pantalone" <fred.pantal...@gmail.com> wrote:
> Here are some resources:
>
> Look for hideMenuItem and/or hideToolbarButton in the docs available
> here:
>
> http://www.adobe.com/devnet/acrobat/javascript.html
>
> In particular, look at the doc entitled "Acrobat JavaScript Scripting
> Guide" and "Acrobat JavaScript Scripting Reference".
>
> Here is some more information:
>
> http://blog.stealthpuppy.com/deployment/deploying-adobe-reader-81
>
> I hope this helps,
> Fred
>
> On Mar 13, 7:13 pm, José Soto <nattio...@gmail.com> wrote:
>
>
>
> > Hello.
>
> > I was reading what Fred posted before and I´m having some trouble
> > trying tohidethe print item from the file menu and the print icon.
> > You said you probably know how to do this... Could you give me some
> > help on this???
>
> > Thanks a lot.-Hidequoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages