Hi,
I'm wondering how we should clear numbers (in single input type: number) conditionally in logic.
When element is text-type we can set '1' or whatever is present but empty (?), but with number-type it's seems like we need another way to clear input value?
In the example (attached json) both types (size: text, size2: number) actually fails in logic gui, but still seems to work. My impression from earlier work is though that it should be working for text-type, but not for number. Either way the question remains if this a correct way of clearing value number-type?
We want to disable this type of elements instead of hiding them, and that is the reason we make the rules in logic/editor.
Hi,
Thank you for sharing a survey JSON.
From what I gather, you wish to reset a single-input text value if a user ticks the 'Size not relevant' box. I see that those logic rules which you configured in the survey JSON works correctly and values of both text inputs are correctly reset:
Would you please elaborate on your question?
Sure. These are configured/modified via JSON editor in order to work.
If you open the logic tab to access these rules you get error when trying to press "done":
I'm wondering if there's a proper way to doo this in logic tab, as error messages makes me wonder if i'm doing something the wrong way
Hello,
Do you want to clear a question value when it becomes disabled?
You can do it for all questions using the following event handler:
survey.onQuestionCreated.add((sender, options) => { const q = options.question; q.registerFunctionOnPropertyValueChanged('readOnly', () => { if (q.readOnly) q.clearValue(); }); });
You can add a customer property to add an additional check.
Here is the example with panel dynamic.
Thank you,
Andrew
SurveyJS Team
Hi Mad,
For the record: I forwarded the following issue to our developers for further consideration.
The Set Value trigger should allow to reset/clear a question value
Thank you
That would be very useful yes!
Is this something to implement a front-end solution and not something i can paste into attached json form file alone?
I can see that there's a reference to when invisible values are cleared in my json, but not sure if it's possible to add something here or where:
], "showQuestionNumbers": "off", "clearInvisibleValues": "onHiddenContainer", "checkErrorsMode": "onValueChanged", "questionsOnPageMode": "singlePage" }
I'm form designer and would push frontend-tasks to developer ;)
And if we have questions that are read only/disabled at all times, would they still keep their value?
Can we trigger "onDisabled/becomes read only" and let other readOnly questions have values still?
Hi Mad,
Thank you for the update.
The clearInvisibleValues option allows you to control whether or not to clear values of hidden questions.
However, as far as I can see, you wish to clear a question value when the question becomes read-only.
The solution suggested by Andrew requires that a developer subscribes to the
survey.onQuestionCreated
function and runs the provided code. If you have questions which are initially set read-only, they will preserve their values. I created the following demo for your reference: https://plnkr.co/edit/IdAWDoji3DW2zFBt.Also, I believe it should be possible to use a Set Value trigger to reset a question value. So, I forwarded the corresponding issue to the development team for further research: The Set Value trigger should allow to reset/clear a question value.
Please look forward to our updates.
Sounds very good. Thank you both!
You're very welcome! Please feel free to contact us at any time.
We hope you enjoyed the level of service you received. If so, we would love if you could leave your feedback on SurveyJS page at g2.com. As we’re building our business, every review helps build credibility for future customers and your feedback would be greatly appreciated.
Hello,
FYI: The issue has been fixed by this PR. The fix should be available in next version that we will release next week.
Thank you,
Andrew
SurveyJS Team