How to deselect a radio button option?

Certified Lead Developer

Hello,

We have a use case where user needs to select only one option out of multiple options. It is not a mandatory field. Radio button helps in ensuring only one option is selected. However, it doesn't allow user to deselect the option. We tried to set the value of Radio button as null when user is selecting the same option again. But it didn't work.

Hence, we are currently using multiple checkbox fields to handle this use case.

Is there a better approach to handle this scenario?

 

Thanks in advance.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    With the advent of Rich Text Links, Rich Text Icons, and the Side-By-Side Layout options, we can probably come up with some creative solutions to this problem now.  In the past I always did what some prior commentors suggested and just put a "None" or "N/A" option.  But this got me thinking.

    What if we used a rich text icon with a dynamic link configured such that it shows up right next to the radio button values?

      ---> 

     

     Here's the code (18.1 required) I came up with for the above:

    load(
      local!radioValue,
      
      a!sectionLayout(
        label: "Radio Button",
        contents: {
          a!textField(
            label: "Text",
            value: "asdf"
          ),
          a!sideBySideLayout(
            alignVertical: "BOTTOM",
            items: {
              a!sideBySideItem(
                width: "MINIMIZE",
                item: a!radioButtonField(
                  label: "Radio",
                  choiceLabels: {"A", "B"},
                  choiceValues: {"A", "B"},
                  value: local!radioValue,
                  saveInto: local!radioValue,
                  /*choiceLayout: "COMPACT",*/
                  required: false()
                )
              ),
              a!sideBySideItem(
                width: "10X",
                item: a!richTextDisplayField(
                  value: a!richtextitem(
                    text: a!richtexticon(
                      caption: "Clear Radio Button Value",
                      icon: "REMOVE"
                    ),
                    link: a!dynamicLink(
                      saveInto: a!save(
                        local!radioValue,
                        null()
                      )
                    ),
                    linkStyle: "STANDALONE"
                  )
                )
              )
            }
          ),
          a!dropdownField(
            label: "Dropdown",
            choiceLabels: {"1", "2"},
            choiceValues: {"1", "2"},
            placeholderLabel: "(Standard Dropdown)"
          )
        }
      )
    )

Reply
  • 0
    Certified Lead Developer

    With the advent of Rich Text Links, Rich Text Icons, and the Side-By-Side Layout options, we can probably come up with some creative solutions to this problem now.  In the past I always did what some prior commentors suggested and just put a "None" or "N/A" option.  But this got me thinking.

    What if we used a rich text icon with a dynamic link configured such that it shows up right next to the radio button values?

      ---> 

     

     Here's the code (18.1 required) I came up with for the above:

    load(
      local!radioValue,
      
      a!sectionLayout(
        label: "Radio Button",
        contents: {
          a!textField(
            label: "Text",
            value: "asdf"
          ),
          a!sideBySideLayout(
            alignVertical: "BOTTOM",
            items: {
              a!sideBySideItem(
                width: "MINIMIZE",
                item: a!radioButtonField(
                  label: "Radio",
                  choiceLabels: {"A", "B"},
                  choiceValues: {"A", "B"},
                  value: local!radioValue,
                  saveInto: local!radioValue,
                  /*choiceLayout: "COMPACT",*/
                  required: false()
                )
              ),
              a!sideBySideItem(
                width: "10X",
                item: a!richTextDisplayField(
                  value: a!richtextitem(
                    text: a!richtexticon(
                      caption: "Clear Radio Button Value",
                      icon: "REMOVE"
                    ),
                    link: a!dynamicLink(
                      saveInto: a!save(
                        local!radioValue,
                        null()
                      )
                    ),
                    linkStyle: "STANDALONE"
                  )
                )
              )
            }
          ),
          a!dropdownField(
            label: "Dropdown",
            choiceLabels: {"1", "2"},
            choiceValues: {"1", "2"},
            placeholderLabel: "(Standard Dropdown)"
          )
        }
      )
    )

Children