Good day,
I am trying to add logical conditions to the visibility of questions in the online survey creator, but the function seems to be broken. I added a simple {Question2} notempty
to the visible if field, but it simply makes the question always invisible.
Weird too is, that I also added a 'required if', but as the question is not visible, it is not filled in, but still I can submit the survey.
How come?
Hello,
Could you please check letters case? If it still doesn't work, please send us your JSON. There are hundreds of unit tests and dozen e2e tests on this functionality. Additionally, a new version is installed by hundreds developers already who definitely use this functionality.
PS: I have just tried it on our online creator and it works.
Thank you,
Andrew
SurveyJS Team
Hello Andrew,
Thank you for your answer. I fiddled around a bit more, and it turns out that my question names were the problem. Apparently logic does not work anymore, as soon as a question name contains a '#'. Is that intentional? Is there a way around this other than not using hashtags anymore? What other characters can't I use?
Working JSON:
{ "locale": "nl", "title": { "nl": "Test survey" }, "logoFit": "none", "logoPosition": "right", "pages": [ { "name": "page1", "elements": [ { "type": "radiogroup", "name": "question1", "title": { "nl": "This is a test question" }, "isRequired": true, "choices": [ { "value": "1", "text": { "default": "Totaal geen moeite", "nl": "And this is a test answer" } }, { "value": "2", "text": { "default": "Veel moeite", "nl": "And this another one" } } ] }, { "type": "rating", "name": "question2", "visibleIf": "{question1} notempty", "title": { "nl": "Rate the last question" }, "rateMin": 0, "rateMax": 10, "minRateDescription": { "nl": "Geen moeite" }, "maxRateDescription": { "nl": "Onmogelijk" } } ] } ], "showTitle": false, "showPageTitles": false, "showCompletedPage": false, "showQuestionNumbers": "off" }
Not working JSON:
{ "locale": "nl", "title": { "nl": "Test survey" }, "logoFit": "none", "logoPosition": "right", "pages": [ { "name": "page1", "elements": [ { "type": "radiogroup", "name": "#question1", "title": { "nl": "This is a test question" }, "isRequired": true, "choices": [ { "value": "1", "text": { "default": "Totaal geen moeite", "nl": "And this is a test answer" } }, { "value": "2", "text": { "default": "Veel moeite", "nl": "And this another one" } } ] }, { "type": "rating", "name": "question2", "visibleIf": "{#question1} notempty", "title": { "nl": "Rate the last question" }, "rateMin": 0, "rateMax": 10, "minRateDescription": { "nl": "Geen moeite" }, "maxRateDescription": { "nl": "Onmogelijk" } } ] } ], "showTitle": false, "showPageTitles": false, "showCompletedPage": false, "showQuestionNumbers": "off" }
Hello Tostiman,
Thank you for the example. We'll research the issue and post updates at https://github.com/surveyjs/survey-library/issues/4911.
Please let us know if any questions remain.
Thank you
To make it works, please use the following code:
Survey.Variable.DisableConversionChar = "$";
The default value is "#".
In the most cases {question1} equals to {#question1}. The only difference, that without "#" prefix, SurveyJS will convert "true" and "false" to boolean value and "12344" to number 12344. If you want to make sure that "true" and "12344" value in "question1" is a string, then you have to use "#" prefix.
Thank you,
Andrew
SurveyJS Team
I am considering replacing all of the #'s with another character. Would you recommend using $ in stead? I prefer using a character that has no additional meaning in surveyjs's code.
I think we have to remove "#" or better say
Survey.Variable.DisableConversionChar
character from question name if it is a first character.Thank you,
Andrew
SurveyJS Team
@Ontkibbeling, please consider another sign (for example, $) to preset a question name. As Andrew noted, we will make changes in our code to prevent starting a question name with the dash # sign.
The example: https://plnkr.co/edit/GESa0dtQfgpbMnKu.
Thank you
Please let us know if you have any question.
Will $ have no interference with any other surveyjs functions?
Yes,
$
will be save.Thank you,
Andrew
SurveyJS Team
Thank you both!
FYI: From the next minor update v.1.9.51 that we are going to release shortly, you will not be able to set "#questionName" into the question name and valueName properties.
Thank you,
Andrew
SurveyJS Team