Question T13467
Visible to All Users

Clear validators once question type is changed

created 2 years ago

Hi there,

We have a custom property called "format" used on question of type "text".

Once we change the value of this format property, we also add a validator to it, according to the option selected

JavaScript
onSettingValue: (text, value) => { text.validators.splice(0, text.validators.length) if (formats[value]?.validator) { text.validators.push(Validator.createInstance(formats[value]?.validator)) } return value },

Now I need to be able to clear the text.validators once the the question type is changed (i.e changing the question from text to dropdown). Is there maybe a callback that is called everytime a question has the type changed?

Thanks,
Luan

Answers approved by surveyjs Support

created 2 years ago

Hello Luan,
We can actually do it out of the box. If a validator type doesn't apply to a new question type, we will remove it.
Will it work for you?

Thank you,
Andrew
SurveyJS Team

    Show previous comments (1)

      Hello Luan,
      The following PR fixes the issue. Unfortunately, we have just released v1.9.92 and the fix will be available in v1.9.93 that we will release next week.

      Thank you,
      Andrew
      SurveyJS Team

        Cool, I'll update once released and I'll let you know if I have any questions / issues…

        Thanks!

          Great!

          Andrew
          SurveyJS Team