chairemobilite / evolution

Online survey platform for travel survey
MIT License
4 stars 9 forks source link

Auto-select (and hide) radio question choice if only a single choice is visible #110

Open davidmurray opened 1 year ago

davidmurray commented 1 year ago

This would be necessary in order to "cleanly" fix issues https://github.com/chairemobilite/od_mtl_2023/issues/395 and https://github.com/chairemobilite/od_mtl_2023/issues/563

davidmurray commented 1 year ago

@tahini Any idea how to implement this in the best way? You are more familiar with the Evolution codebase than I am :)

tahini commented 1 year ago

I have no easy solution for now unfortunately, as choices and conditional are 2 fields of the widget itself. And both are called in quite different places (the redux action and the widget render). Ideally, if the conditional could know about choices, get the choices and auto-select the choice if only one, but ti doesn't cleanly know about that...

This would require some core changes to do... In the survey itself though, one can extract the applicable choices, function that is called in the choices field and the conditional. The conditional addtionally checks the number of applicable choice elements.

But if you drop the "hide" requiremenet, the InputRadio component could simply add the select={true} if there's only one choice and make sure to call the onValueChange with that choice's value.

davidmurray commented 1 year ago

This would require some core changes to do... In the survey itself though, one can extract the applicable choices, function that is called in the choices field and the conditional. The conditional addtionally checks the number of applicable choice elements.

Seems like a good solution for now. Considering the huge backlog of issues in od_mtl_2023, I think we should go with this. :) Thanks

kaligrafy commented 1 year ago

Is this fixed by #592?

davidmurray commented 1 year ago

Kind of but it’s a bit of a hack. Ideally there would be a better way to do this directly in evolution