Question T7521
Visible to All Users

Multiple mutually exclusive checkbox items with custom values

created 3 years ago (modified 3 years ago)

Hi there,

I've been developing a large health survey using SurveyJS. We have mostly been using the Survey Creator.

Some of our questions are checkbox lists. For instance:

Which of these health conditions do you have?

  • Asthma (1)
  • Heart disease (2)
  • Allergies (3)
  • None of the above (-97)
  • Prefer not to answer (-98)

I would like to set it so choosing 'None of the above' OR 'Prefer not to answer' automatically deselects the other options. And then if you choose 1-3, the mutually exclusive options are automatically deselected. Moreover, it is important the value is as above, rather than the text value 'none' that appears for the 'has none option' in the Survey Builder.

I have tried implementing this code: https://plnkr.co/edit/H1YjYH?p=preview&preview but this does not work - it will deselect all other options when the -97 is selected, but then one can select other options and the -97 remains in place.

Would you be able to recommend a solution?

Answers approved by surveyjs Support

created 3 years ago

Hello,

You can use the hasNone option as shown in this live plunker sample - https://plnkr.co/edit/5Wyg7LWYxj9SeY7Z

Thanks, Serge
SurveyJS Team

    Comments (3)
    CH CH
    Charlotte Huggins 3 years ago

      Hi Serge,

      I'm sorry, that does not address our issue at all. We are currently using hasNone and it doesn't address our needs.

      The issue is twofold:

      1. We need to be able to have multiple mutually exclusive checkbox items. So Just one 'None' option is not helpful. For some instance, we need to be able to have 'None of the above', 'Prefer not to say' and 'Don't know', for instance. All three of these options need to be mutually exclusive.
      2. We need to be able to set the value of the mutually exclusive checkbox item to a specific value. At the minute it feeds through as text "none". We need to set it to something else.

      Please let me know if you have a solution to either of these problems.

      All the best,
      Charlotte

        Hello Charlotte,
        Here is the working example. Please note, that I'm using the latest version and onValueChanging event. You don't need necessary to use the latest version, but at least not so old version that doens't have onValueChanging event that we have added some times ago, likely more than an year.

        Thank you,
        Andrew
        SurveyJS Team

        CH CH
        Charlotte Huggins 3 years ago

          Hi Andrew,

          That works beautifully, thank you very much! That saves us a lot of time and effort both now and when we get the data. I really appreciate it!

          Thank you!
          Charlotte