Yes/No Question
A Yes/No, or Boolean, question asks respondents to select between two options: yes or no, true or false, etc. Boolean questions can be used to implement conditional survey logic or as standalone questions. This example demonstrates how to create and configure a Boolean question in SurveyJS Form Library. Switch between Angular, React, Knockout, jQuery, and Vue to view an example for your JavaScript framework.
Create a Yes/No Question
To create a Boolean question, define an object with the type
property set to "boolean"
and add it to the elements
array. Within this object, specify the question's title
and a unique name
that identifies the question.
Change Positive and Negative Text Labels
A Boolean question displays "Yes" for the positive answer and "No" for the negative answer. Use the labelTrue
and labelFalse
properties to change the displayed text labels. In this demo, you can use Settings to change the labels at runtime.
Save Custom Values for true
and false
Survey results store true
or false
as an answer to a Boolean question. If you want to save custom values instead, assign them to the valueTrue
and valueFalse
properties. You will still be able to access the selected Boolean value via the booleanValue
property. In this demo, Boolean questions save "Yes" or "No" in survey results.
Change Display Mode
Boolean questions support the following UI modes:
- Slider
- Radio button group
- Checkbox
The slider mode automatically applies when labels are short; the radio button group mode—when they are long. To use a specific display mode, set the renderAs
property to "radio"
or "checkbox"
. This example demonstrates all three display modes.