Question T19323
Visible to All Users

Default Value - on removing the choice in dropdown

created 5 months ago

Hi,
I facing an issue where selecting the default value for the drop down, if appears correctly in the json object. after that If I change the choice to remove the choice which was selected in the default value, but it remains there.
The JSON object looks likes this

JSON
"pages": [ { "name": "page1", "elements": [ { "type": "checkbox", "name": "question1", "defaultValue": [ "Item 1" ], "choices": [ "Item 2", "Item 3" ] } ] } ],

the goal
I would like to set the deyfault value to empty if the choices does not have that default value choice anyore.
how can I do that?

Answers approved by surveyjs Support

created 5 months ago

Hello Haris,
You can implement it by yourself using creator.onSurveyPropertyValueChanged event.
Here is the working example.

Thank you,
Andrew
SurveyJS Team

    Show previous comments (1)

      Please cast obj to <any>.

      Thank you,
      Andrew
      SurveyJS Team

        Alright thanks. that worked.
        still struggling with Survey.ItemValue.getItemByValue(obj.choices, obj.defaultValue.
        from where should I import Survey it in a react application?

          It should be:

          JavaScript
          import { ItemValue } from "survey-core"; if(!ItemValue.getItemByValue(obj.choices, obj.defaultValue))

          Thank you,
          Andrew
          SurveyJS Team