Extend Multiple Choice with select all option functionality

jason zerr asked on September 27, 2018 22:00

Is it possible to inherit from multiple choice form control and add functionality to select all checkboxes in multiple choice form control, I also looked into custom controls but cannot figure out how the set value for those checkboxes will work. Currently I am using a SQL Query to get values for multiple choice form control.

Correct Answer

Trevor Fayas answered on September 28, 2018 06:18

I would take the simple route. All you need is a button or check box above your control to on click/check to use JavaScript to set all the input (type check box) to checked.

You can do this by cloning the form control and adding the functionality to the cloned ascx file (best wrap it in a div so the JavaScript can look for all inputs contained by the parent div). Do you need JavaScript sample or are you capable of doing that?

1 votesVote for this answer Unmark Correct answer

Recent Answers


Trevor Fayas answered on September 28, 2018 01:24

Just wrote a blog article on extending your controls using the ControlExtender, you can create a form control inherited from it (see https://docs.kentico.com/k11/custom-development/developing-form-controls/inheriting-from-existing-form-controls ) and overwrite some of the features.

What you mean by "Select all checkboxes" will change what you do though. If you want all of them selected by default, then you should be able to extend it to set the option values to checked, as long as the values are created on the OnInit(e) and before you call base.OnInit(e) (since it's on the base.OnInit(e) that your ControlExtender will fire).

If you want to add some thing to allow users to select them all, then you may be better off cloning and adding more controls and such, as that's a little more than just extending what's there.

If you can provide more detail that would help!

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on September 28, 2018 02:09 (last edited on December 10, 2019 02:31)

I guess you are looking for for all check boxes selected by default i.e. on load? Here is an example. Essentialy you need to reproduce all checkbox values pipe separated. If the values for checkbox list comes from SQL query you need to create a custom macro that will output pipe separated values. If it comes from custom table you can do it using built-in macro syntax. Let say your custom table calle dropdown and the valued field is ItemId, you can put as default value this macro: {% string.Join("|", GlobalObjects.CustomTables["CustomTable.DropDown"].Items.ItemsAsFields.ItemID|(identity)GlobalAdministrator%}

The other way would be simply to add button and jquery to content before:

<div id=checkdiv>
 <input type="button" class="check" value="check all" />
    <script>
      $cmsj(function(){
        $cmsj('.check:button').click(function(){
              var checked = !$cmsj(this).data('checked');
              $cmsj('#checkdiv input:checkbox').prop('checked', checked);
              $cmsj(this).val(checked ? 'uncheck all' : 'check all' )
              $cmsj(this).data('checked', checked);
        });
       });
    </script>

and after </div>

0 votesVote for this answer Mark as a Correct answer

jason zerr answered on September 28, 2018 03:39

@Trevor Fayas I am trying to implement control that allows user to select all the checkbox generated by multiple choice form control. Basically a select all checkbox will mark all other inputs as checked if selected. But I am not sure how should I go about it.

0 votesVote for this answer Mark as a Correct answer

jason zerr answered on September 28, 2018 12:46

@Trevor Fayas Thanks a-lot, I would be able to do that now that you have made it clear.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.