I'm developing a custom property to be used in the property grid. The goal of the property is to allow users to select from a dropdown which "attribute" they want to link to a question.
This attribute is a part of the project's business domain and some SurveyJS properties can be automatically set based on the attribute selection. In short: the business domain model aims to impose some structure on the survey builder for domain validation etc.
One of the SurveyJS properties influenced by the attribute is the JSON property the question's answer will be serialised to (valueName
), this is how it's currently being set:
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);
}
Ignore how the choices are being loaded, this is done in this way because the custom SurveyJS widgets, expressions and attributes we're developing are part of a shared library.
The above works as expected, meaning that when I select an option from the dropdown, the valueName
property is set accordingly and completing the survey will result in a JSON using the property names based on the attribute selection.
However, I would like to fix the following scenario (this happens in the Survey Builder):
- I select a question and change the DomainAttribute property
- I deselect that question
- I select it again, the custom property does not automatically reselect the value in the dropdown
I would like to be able to, either on focus of the question or on loading of the choices, read the question's valueName
property and use this to select the correct value in the choices list, but I cannot find documentation on whether or not this would be possible.
Many thanks for anyone who could point me in the right direction.