Only allow 1 or 0 marked options in a checkgroup

From pmusers
Jump to: navigation, search

This example shows how to only allow one or zero marked options in a checkgroup. The previously marked options will be unmarked with JavaScript.


Dynaform: Only_0_or_1_marked_options_in_checkgroup.json (right click and select Save Link As)
Author: Amos Batto (amos@processmaker.com)
Version: 1.0 (2019-01-29)
Tested in: PM 3.3.0 Community in Debian 9.5 with Firefox 52


Create a Dynaform with a checkgroup that has 2 or more options.

CheckgroupInDesigner.png

In this example, the checkgroup has the ID "selectCountry", and it has the following options:

OptionsInCheckgroup.png

To prevent more than one option from being marked at a time in the checkgroup, add the following JavaScript to the Dynaform:

var checkgroupId = "selectCountry"; //set to ID of checkgroup

$("#"+checkgroupId).find("[name='form["+checkgroupId+"][]']").change( function() {
  var aNew = [ this.value ];
  $("#"+checkgroupId).setValue(aNew);
});

Change the checkgroupId to the ID of the checkgroup.

Now, no more than one option can be marked at a time in the checkgroup.

OnlyOneMarkedOptionInCheckgroup.png