Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Problem with checkboxes in LiveCycle 8.2

Avatar

Former Community Member

Hallo there!

I have a problem to set checkboxes behavior. I have 10 checkboxes in the vote list. I'm trying to set those to act on this way: when someone mark 5/10 checkboxes, other 5 are not accessible anymore.

Is it possible to do this?

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

You need to scripts in the click event and the layout:ready event of each checkbox. In addition you need either a field to keep track of scores or a global variable to do this. Here I have used a numeric field.

The script in the click event adds the score (or takes 1 away if a checkbox is deselected):

if (this.rawValue == "1")

{

     score.rawValue += 1;

}

else

{

     score.rawValue -= 1;

}

In the layout:ready event of each checkbox it looks at the value of the checkbox and the score, then sets the access:

if (this.rawValue == "0" && score.rawValue == 5)

{

     this.access = "readOnly";

}

else

{

     this.access = "open";

}

It only locks the checkboxes that are not already checked, so that the user can deselect a checkbox.
Hope that helps,
Niall

View solution in original post

11 Replies

Avatar

Correct answer by
Level 10

Hi,

You need to scripts in the click event and the layout:ready event of each checkbox. In addition you need either a field to keep track of scores or a global variable to do this. Here I have used a numeric field.

The script in the click event adds the score (or takes 1 away if a checkbox is deselected):

if (this.rawValue == "1")

{

     score.rawValue += 1;

}

else

{

     score.rawValue -= 1;

}

In the layout:ready event of each checkbox it looks at the value of the checkbox and the score, then sets the access:

if (this.rawValue == "0" && score.rawValue == 5)

{

     this.access = "readOnly";

}

else

{

     this.access = "open";

}

It only locks the checkboxes that are not already checked, so that the user can deselect a checkbox.
Hope that helps,
Niall

Avatar

Former Community Member

Niall, can i ask you one more?

How to set those 5 checkboxes to be required? So, if someone want to complete the vote list,  5/10 checkboxes must be marked.

Thanks  

Avatar

Level 10

Hi,

It depends on what the following action is. Is the form being submitted?

One option would be to not assign the checkboxes as required, but track the score value. For example the submit button would be hidden/readOnly unless the score was 5.

In that case the submit button could have the following in the layout:ready event

if (score.rawValue == 5)

{

     this.presence = "visible";

}

else

{

     this.presence = "invisible";

}

You can script an object to be required, but I think it is a bit too much trouble here as you don't know which of the 10 the user will tick and you would then have to turn off the required status on the 5 remaining un-ticked ones.

Let me know what you think,

Niall

Avatar

Level 7

If either of you is interested, John Brinkman wrote a blog entry about this. You can read it here if you'd like:

http://blogs.adobe.com/formfeed/2008/12/adventures_with_javascript_obj.html

Avatar

Former Community Member

Hi,

Yes, the vote list contains e-mail submit button and hide/readonly option sounds good. But I have 3 different groups of checkboxes/candidates on the single page. I did scrypting as you told me in the first answer and everything works beautiful (look the link).

https://acrobat.com/#d=Ek-jpQcSCDz770G-yOstfQ

first group: I allow and require 5 marked checkboxes.

second group: I allow and require 3 marked checkboxes.

third group: I allow and require 2 marked checkboxes. 

Now, how to scrypt submit button?...or maybe there is some other solution...hope you understand what i'm trying to do....

thanks for helping me

Avatar

Level 10

Hi,

You will be able to test against the three separate scores and then change the visibility of the submit button. If just need s simple if statement, something like:

if (score1.rawValue == 5 && score2.rawValue == 3 && score3.rawValue == 2)

{

     this.presence = "visible";

}

else

{

     this.presence = "invisible";

}

I can't access the file you put on Acrobat.com - you will need to share it and click OK to save the share.

It's St. Patrick's Day here, so I won't be able to get to it for a few hours.

Niall

Avatar

Former Community Member

Thanks!

I put the file on share, so when you have a time.

Enjoy celebration

Marko

Avatar

Level 10

Thank you,

Here is the form: https://acrobat.com/#d=xdgAZtSFsa0ky890ZeXUJw

Check out the script in the layout:ready event of the submit button. Because the button is hidden, you could include a bit of text to let the user know that when they complete the checkboxes, the submit button will be available.

Script in the layout:ready event isn't the most efficient because it fires at each change in the form. But if the form is short it won't affect performance too much.

Slan,

Niall

Avatar

Former Community Member

Just great

I became interested in javascript. There is a lot to learn.

Thanks for the help!

Marko