Skip to main content

GetChoiceName

Returns the choice name of the current radio button.

Syntax

expression.GetChoiceName();

expression - A variable that represents a ApiCheckBoxForm class.

Parameters

This method doesn't have any parameters.

Returns

string

Example

Create a form with three radio buttons and specify choice names for each radio button. The radio buttons are grouped together by setting the same radio group key for each radio button. The radio group key is displayed at the end of the document in a document.

// How to get the choice name for a checkbox form?

// Get the choice name and display the result in a document.

let doc = Api.GetDocument();

// Create first radio button
let checkBoxForm = Api.CreateCheckBoxForm({
"tip": "Select your preferred contact method",
"required": true,
"placeholder": "Contact preference",
"radio": true
});
checkBoxForm.SetRadioGroup("ContactPreference");
checkBoxForm.SetChoiceName("Email");
let paragraph = doc.GetElement(0);
paragraph.AddElement(checkBoxForm);
paragraph.AddText(" Email");
paragraph.AddLineBreak();

// Create second radio button
checkBoxForm = Api.CreateCheckBoxForm({
"tip": "Select your preferred contact method",
"required": true,
"placeholder": "Contact preference",
"radio": true
});
checkBoxForm.SetRadioGroup("ContactPreference");
checkBoxForm.SetChoiceName("Phone");
paragraph.AddElement(checkBoxForm);
paragraph.AddText(" Phone");
paragraph.AddLineBreak();
checkBoxForm.SetChecked(true);

// Create third radio button
checkBoxForm = Api.CreateCheckBoxForm({
"tip": "Select your preferred contact method",
"required": true,
"placeholder": "Contact preference",
"radio": true
});
checkBoxForm.SetRadioGroup("ContactPreference");
checkBoxForm.SetChoiceName("Mail");
paragraph.AddElement(checkBoxForm);
paragraph.AddText(" Mail");

// Find the selected radio button and display the choice name
let radioGroup = checkBoxForm.GetRadioGroup();
paragraph = Api.CreateParagraph();
doc.GetAllForms().forEach(form => {
if ("ContactPreference" === form.GetRadioGroup() && form.IsChecked()) {
let choiceName = form.GetChoiceName();
paragraph.AddText("Selected option: " + choiceName);
}
});
doc.Push(paragraph);