CheckBox visibility Function

i want to display a text box only when a check box is been clicked. what can i do to achieve that?

  Discussion posts and replies are publicly visible

  • 0
    Certified Senior Developer

    hi, Please go through below sample code and you can modify according to your requirements. The idea here is to configure the "showWhen" parameter of the text field. configure this parameter with a boolean variable which gets changed based on checkbox selection.

    a!localVariables(
      local!selectedChoice:false,
      {
        a!checkboxField(
          label: "checkbox",
          choiceLabels: {"Yes","No"},
          choiceValues: {true,false},
          value: local!selectedChoice,
          saveInto: local!selectedChoice
        ),
        a!textField(
          label: "text field",
          showWhen: local!selectedChoice
        )
      }
    )

  • 0
    Certified Associate Developer

    hi, if you want to display specific box or multiple boxes while selecting the check box, then you can modify the below code as you desire.

    a!localVariables(
      local!selectedBox,
      {
        a!checkboxField(
          choiceLabels: { "a", "b" },
          choiceValues: { 1, 2 },
          value: local!selectedBox,
          saveInto: local!selectedBox,
    
        ),
        a!textField(
          showWhen: {
            and(
              a!isNotNullOrEmpty(local!selectedBox),
              local!selectedBox = 1
            )
          },
          label: "text field 1"
        ),
        a!textField(
          showWhen: {
            and(
              a!isNotNullOrEmpty(local!selectedBox),
              local!selectedBox = 2
            )
          },
          label: "text field 2"
        )
      }
    )