I am currently working on designing a custom property for the property grid that will allow users to choose from a dropdown menu which "attribute" they want to link to a specific question.
This attribute is essential in the project's business domain, and certain SurveyJS properties can be automatically configured based on the selected attribute. Essentially, the business domain model is intended to provide structure to the survey builder for domain validation purposes.
One of the SurveyJS properties affected by the attribute is the JSON property where the question's answer will be serialized into (valueName
). This is how it is currently being implemented:
import { SurveyModel } from 'survey-core';
let choicesOptions : string[] = [];
export function setDomainAttributeChoices(choices: string[] ){
choicesOptions = choices;
}
export const domainAttributeProperty = {
name: 'DomainAttributeProperty',
category: 'general',
choices: loadChoices,
visibleIndex: 0,
onSetValue: onSetValue
}
function loadChoices(obj: unknown, cb: Function) {
cb(choicesOptions);
}
function onSetValue(survey: SurveyModel, value: string): void {
survey.setPropertyValue('valueName', value);
}
Please disregard the way choices are loaded; this method was chosen due to the nature of our shared library containing custom SurveyJS widgets, expressions, and attributes.
The current implementation works as expected – selecting an option from the dropdown sets the valueName
property accordingly, resulting in a JSON output using the property names based on the attribute selection upon survey completion.
However, I would like to address the following issue (which occurs in the Survey Builder):
- I select a question and change the DomainAttribute property
- I deselect the question
- I select it again, but the custom property does not automatically reselect the previous value in the dropdown
I would like to have the ability, either upon focus of the question or during choice loading, to retrieve the question's valueName
property and use it to automatically select the correct value in the choices list. Unfortunately, I have been unable to find documentation addressing whether this is possible.
If anyone could provide guidance on this matter, I would greatly appreciate it. Thank you!