How to add group checkboxes to the document using BoldSign API?

Group Checkboxes allow you to apply validation rules across multiple checkbox fields, ensuring that users select a specified number of checkboxes within a group. This feature is particularly useful in scenarios like surveys or forms, where it's necessary to restrict or mandate the number of options a user can choose.

Validation types in group checkboxes dictate how many checkboxes must be selected, enforcing conditions such as a minimum, maximum, or exact number of selections. This ensures that user input aligns with the desired criteria, improving the accuracy and consistency of the data collected.

Following are the validation types available for group checkbox

  • Maximum: Specifies the maximum number of checkboxes that can be selected.
  • Minimum: Specifies the minimum number of checkboxes that must be selected, with the option to select more if needed.
  • Absolute: Specifies the exact number of checkboxes that must be selected. Both minimumCount and maximumCount should be the same.
  • Range: Allows a range of checkboxes to be selected between a minimum and maximum value.

In this article, we'll explore how to add group checkbox fields to a document via the BoldSign API.Lets see the code examples as follows:

Code snippet

curl -X 'POST' \
  'https://api.boldsign.com/v1/document/send' \
  -H 'accept: application/json' \
  -H 'X-API-KEY: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "title": "Send Document",
    "files": [
        "data:application/pdf;base64,JVBERi0xLjcKJcfs..."
    ],
    "signers": [
        {
            "name": "{Signer name}",
            "signerOrder": 1,
            "emailAddress": "{Signer email}",
            "signerType": "Signer",
            "FormFields": [
                {
                    "fieldType": "CheckBox",
                    "id": "check1",
                    "pageNumber": 1,
                    "bounds": {
                        "X": 100,
                        "Y": 100,
                        "Width": 30,
                        "Height": 30
                    },
                    "isRequired": true,
                    "groupName": "checkgroup1"
                },
                {
                    "id": "check2",
                    "fieldType": "CheckBox",
                    "pageNumber": 1,
                    "bounds": {
                        "X": 130,
                        "Y": 100,
                        "Width": 30,
                        "Height": 30
                    },
                    "isRequired": true,
                    "groupName": "checkgroup1"
                },
                {
                    "fieldType": "CheckBox",
                    "id": "check11",
                    "pageNumber": 1,
                    "bounds": {
                        "X": 300,
                        "Y": 300,
                        "Width": 30,
                        "Height": 30
                    },
                    "isRequired": true,
                    "groupName": "checkgroup2"
                },
                {
                    "id": "check21",
                    "fieldType": "CheckBox",
                    "pageNumber": 1,
                    "bounds": {
                        "X": 350,
                        "Y": 300,
                        "Width": 30,
                        "Height": 30
                    },
                    "isRequired": true,
                    "groupName": "checkgroup2"
                }
            ]
        }
    ],
    "formGroups": [
        {
            "maximumCount": 2,
            "groupNames": [
                "checkgroup1"
            ],
            "groupValidation": "Maximum"
        },
        {
            "minimumCount": 1,
            "groupNames": [
                "checkgroup2"
            ],
            "groupValidation": "Minimum"
        }
    ]
}'
var apiClient = new ApiClient("https://api.boldsign.com", "{Your API key}");
var documentClient = new DocumentClient(apiClient);

var documentFilePath = new DocumentFilePath
{
    ContentType = "application/pdf",
    FilePath = "{Your File path}"
};

var filesToUpload = new List<IDocumentFile>
{
    documentFilePath,
};

var formFields = new List<FormField>();

formFields.Add(new FormField(
    name: "check1",
    type: FieldType.CheckBox,
    pageNumber: 1,
    bounds: new Rectangle(x: 200, y: 250, width: 30, height: 30)));

formFields.Add(new FormField(
    name: "check2",
    type: FieldType.CheckBox,
    pageNumber: 1,
    bounds: new Rectangle(x: 230, y: 250, width: 30, height: 30)));

formFields.Add(new FormField(
    name: "check3",
    type: FieldType.CheckBox,
    pageNumber: 1,
    bounds: new Rectangle(x: 200, y: 450, width: 30, height: 30)));

formFields.Add(new FormField(
    name: "check4",
    type: FieldType.CheckBox,
    pageNumber: 1,
    bounds: new Rectangle(x: 230, y: 450, width: 30, height: 30)));

formFields[0].GroupName = "checkGroup1";
formFields[1].GroupName = "checkGroup1";
formFields[2].GroupName = "checkGroup2";
formFields[3].GroupName = "checkGroup2";


var signer = new DocumentSigner(
  signerName: "David",
  signerType: SignerType.Signer,
  signerEmail: "ranjitha.amirthalingam+1@syncfusion.com",
  formFields: formFields);

var documentSigners = new List<DocumentSigner>()
{
    signer
};

var groupNames = new List<string>() { "checkGroup1" };
var groupNames2 = new List<string>() { "checkGroup2" };

var formGroups = new List<FormGroup>()
{
    new FormGroup(groupNames: groupNames, groupValidation: GroupValidation.Minimum)
    {
        MinimumCount = 1
    },
    new FormGroup(groupNames: groupNames2, groupValidation: GroupValidation.Maximum)
    {
        MaximumCount = 2
    }
};

var sendForSign = new SendForSign()
{
    Message = "please sign this",
    Title = "Agreement",
    Signers = documentSigners,
    Files = filesToUpload,
    FormGroups = formGroups
};

var documentCreated = documentClient.SendDocument(sendForSign);
import requests

url = "https://api.boldsign.com/v1/document/send"
payload = {
    "title": "Send Document",
    "files": ["data:application/pdf;base64,JVBERi0xLjcKJcfs..."],
    "signers": [
        {
            "name": "{Signer name}",
            "signerOrder": 1,
            "emailAddress": "{Signer email}",
            "signerType": "Signer",
            "FormFields": [
                {
                    "fieldType": "CheckBox",
                    "id": "check1",
                    "pageNumber": 1,
                    "bounds": {"X": 100, "Y": 100, "Width": 30, "Height": 30},
                    "isRequired": True,
                    "groupName": "checkgroup1"
                },
                {
                    "id": "check2",
                    "fieldType": "CheckBox",
                    "pageNumber": 1,
                    "bounds": {"X": 130, "Y": 100, "Width": 30, "Height": 30},
                    "isRequired": True,
                    "groupName": "checkgroup1"
                },
                {
                    "fieldType": "CheckBox",
                    "id": "check11",
                    "pageNumber": 1,
                    "bounds": {"X": 300, "Y": 300, "Width": 30, "Height": 30},
                    "isRequired": True,
                    "groupName": "checkgroup2"
                },
                {
                    "id": "check21",
                    "fieldType": "CheckBox",
                    "pageNumber": 1,
                    "bounds": {"X": 350, "Y": 300, "Width": 30, "Height": 30},
                    "isRequired": True,
                    "groupName": "checkgroup2"
                }
            ]
        }
    ],
    "formGroups": [
        {
            "maximumCount": 2,
            "groupNames": ["checkgroup1"],
            "groupValidation": "Maximum"
        },
        {
            "minimumCount": 1,
            "groupNames": ["checkgroup2"],
            "groupValidation": "Minimum"
        }
    ]
}
headers = {
    "accept": "application/json",
    "X-API-KEY": "YOUR_API_KEY",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)

const axios = require("axios");
const fs = require("fs");

const payload = {
  title: "Send Document",
  files: ["data:application/pdf;base64,JVBERi0xLjcKJcfs..."],
  signers: [
    {
      name: "{Signer name}",
      signerOrder: 1,
      emailAddress: "{Signer email}",
      signerType: "Signer",
      FormFields: [
        {
          fieldType: "CheckBox",
          id: "check1",
          pageNumber: 1,
          bounds: { X: 100, Y: 100, Width: 30, Height: 30 },
          isRequired: true,
          groupName: "checkgroup1",
        },
        {
          id: "check2",
          fieldType: "CheckBox",
          pageNumber: 1,
          bounds: { X: 130, Y: 100, Width: 30, Height: 30 },
          isRequired: true,
          groupName: "checkgroup1",
        },
        {
          fieldType: "CheckBox",
          id: "check11",
          pageNumber: 1,
          bounds: { X: 300, Y: 300, Width: 30, Height: 30 },
          isRequired: true,
          groupName: "checkgroup2",
        },
        {
          id: "check21",
          fieldType: "CheckBox",
          pageNumber: 1,
          bounds: { X: 350, Y: 300, Width: 30, Height: 30 },
          isRequired: true,
          groupName: "checkgroup2",
        },
      ],
    },
  ],
  formGroups: [
    {
      maximumCount: 2,
      groupNames: ["checkgroup1"],
      groupValidation: "Maximum",
    },
    {
      minimumCount: 1,
      groupNames: ["checkgroup2"],
      groupValidation: "Minimum",
    },
  ],
};

const response = await axios.post(
  "https://api.boldsign.com/v1/document/send",
  payload,
  {
    headers: {
      "Content-Type": "application/json",
      accept: "application/json",
      "X-API-KEY": "{your API key}",
    },
  }
);
console.log(response.data);
<?php
$url = 'https://api.boldsign.com/v1/document/send';

$data = array(
    "title" => "Send Document",
    "files" => array("data:application/pdf;base64,JVBERi0xLjcKJcfs..."),
    "signers" => array(
        array(
            "name" => "{Signer name}",
            "signerOrder" => 1,
            "emailAddress" => "{Signer email}",
            "signerType" => "Signer",
            "FormFields" => array(
                array(
                    "fieldType" => "CheckBox",
                    "id" => "check1",
                    "pageNumber" => 1,
                    "bounds" => array("X" => 100, "Y" => 100, "Width" => 30, "Height" => 30),
                    "isRequired" => true,
                    "groupName" => "checkgroup1"
                ),
                array(
                    "id" => "check2",
                    "fieldType" => "CheckBox",
                    "pageNumber" => 1,
                    "bounds" => array("X" => 130, "Y" => 100, "Width" => 30, "Height" => 30),
                    "isRequired" => true,
                    "groupName" => "checkgroup1"
                ),
                array(
                    "fieldType" => "CheckBox",
                    "id" => "check11",
                    "pageNumber" => 1,
                    "bounds" => array("X" => 300, "Y" => 300, "Width" => 30, "Height" => 30),
                    "isRequired" => true,
                    "groupName" => "checkgroup2"
                ),
                array(
                    "id" => "check21",
                    "fieldType" => "CheckBox",
                    "pageNumber" => 1,
                    "bounds" => array("X" => 350, "Y" => 300, "Width" => 30, "Height" => 30),
                    "isRequired" => true,
                    "groupName" => "checkgroup2"
                )
            )
        )
    ),
    "formGroups" => array(
        array(
            "maximumCount" => 2,
            "groupNames" => array("checkgroup1"),
            "groupValidation" => "Maximum"
        ),
        array(
            "minimumCount" => 1,
            "groupNames" => array("checkgroup2"),
            "groupValidation" => "Minimum"
        )
    )
);

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\n" .
                     "accept: application/json\r\n" .
                     "X-API-KEY: YOUR_API_KEY\r\n",
        'method'  => 'POST',
        'content' => json_encode($data),
    ),
);

$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {
    // Handle error
}
print_r($result);
?>

By updating group checkboxes with validation, you control user interactions, ensuring they comply with required conditions for document signing.