Closed JaneSjs closed 8 months ago
It is impossible to achieve the goal by using this path. isRequired is "false" by default and we do not store in JSON the default properties values, otherwise our JSONs would be huge. Because, there is no "false" property set into JSON, there is noway to override your "default" true
value that you set in the internal question.
The task has to be implemented in the different way. Basically, we want to have another default value for isRequired property for "country" question type.
These two lines should be removed:
inheritBaseProps: ["isRequired"],
and
isRequired: true
and set the default value for isRequired for "country" question type:
Survey.Serializer.getProperty("country", "isRequired").defaultValue = true;
findProperty
function can't be used because it will return the base question "isRequired" property. By modifying it's attributes, the behavior of all questions will be modified.
getProperty
function should be used instead. It will create the "copy" of the base "isRequired" property. All it's attributes will be copied and the new property defintion will be related to "country" type and it's descendants.
Here is the final code:
Survey.ComponentCollection.Instance.add({
name: "country",
title: "Country",
questionJSON: {
type: "text",
placeholder: "Select a country...",
},
});
Survey.Serializer.getProperty("country", "isRequired").defaultValue = true;
Here is the working example.
Thank you, Andrew
T17332 - isRequired in custom question types https://surveyjs.answerdesk.io/internal/ticket/details/T17332
The
isRequired
property is defined within an array of properties inherited from a base Text question. TheisRequired
option is defined within the custom component configuration.However, if you uncheck this option in designer, the option remains enabled in Preview: View Demo.
![Uploading image.png…]()