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
SOLVED

How to enfore checkbox field must check two item?

Avatar

Level 3

Hello,

 

I have a question. I want the checkbox field must check two item? How to implement?

 

Thanks for any reply.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

I meant to say you can write a script to validate if the required checkboxes are checked or not.

For that, you can give a button and write a script on that for checking whether the required field is checked or not.

or Can write the script on the checkbox to check whether any two check box selected in that question.

View solution in original post

8 Replies

Avatar

Employee Advisor

@fulongt37334138  what kind of form is it?

 

1. PDF Then you need to write a script on exit to validate if two are selected or not

2. Same logic as 1 in case of adaptive form on value commit and validate

Avatar

Level 3

Hi Mayank_Gandhi,

 

Very thanks for you reply. Could you tell me more? or give me some example?

 

Best Regards

Flo Tang

Avatar

Employee Advisor

Hi @fulongt37334138 ,

 

This is for pdf form or adaptive I will share the code accordingly. 

Avatar

Community Advisor

What do you mean check 2 items? Is it like you want to check 2 checkboxes on checking one checkbox?

 

If this is the case then you can do like below:

 

In java script: eg. checkbox on/off values are 0/1

form1.CheckBox1::click - (JavaScript, client)
if(this.rawValue == 1){
CheckBox2.rawValue =1;
}else{
CheckBox2.rawValue =0;
}

 

 

or You can map the 2 checkboxes with the same node in schema if you are using one.

Avatar

Level 3

Hi Vijay_Katoch,

 

If I make a multiselect question with 5 items, and student must choose two items, how to implement?

 

Thanks very much.

Avatar

Community Advisor

You need to check the value of those items to make sure that 2 are selected. You can do that in validate form button.

Avatar

Level 3

Hi Vijay_Katoch

 

You said I can do that in validate form button. What is a validate form button, how can I do this? I cannot find anything from official document.

 

Thanks very much

Avatar

Correct answer by
Community Advisor

I meant to say you can write a script to validate if the required checkboxes are checked or not.

For that, you can give a button and write a script on that for checking whether the required field is checked or not.

or Can write the script on the checkbox to check whether any two check box selected in that question.