Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add ability for checkbox element to comply with isRequired. #32

Closed
laogao opened this issue Apr 5, 2023 · 4 comments
Closed

Comments

@laogao
Copy link
Contributor

laogao commented Apr 5, 2023

When a checkbox question is set as isRequired, user has to at least check one box for the question.

@ChopinDavid
Copy link
Contributor

ChopinDavid commented Apr 7, 2023

Our team was just having this conversation. We weren't 100% sure what the behavior for isRequired on a checkbox would look like, but assumed that it means that at least one box must be checked for it to validate. We would maybe need to see how required checkboxes on the officially supported web frameworks behave and mimic this behavior.

@laogao
Copy link
Contributor Author

laogao commented Apr 10, 2023

Our team was just having this conversation. We weren't 100% sure what the behavior for isRequired on a checkbox would look like, but assumed that it means that at least one box must be checked for it to validate. We would maybe need to see how required checkboxes on the officially supported web frameworks behave and mimic this behavior.

This is probably best evaluated together with issue #33 . Here's what I've found out based on the JS version of survey.js:

  1. When hasSelectAll is enabled, either this "select-all" choice is checked (which means all regular choices are checked) or any other choices are checked, the isRequired validation is passed;
  2. When hasNone is enabled, either this "none" choice is checked (which means all regular choices are unchecked) or any other choices are checked, the isRequired validation is passed;
  3. When hasOther is enabled, either this "other" choice is checked (which means a corresponding input box would show up) and additional input is provided, or any other choices are checked, the isRequired validation is passed;
  4. When hasOther is enabled, and this "other" choice is checked, but the user hasn't yet provided additional text for the corresponding input box, the isRequired validation is not passed.

@laogao
Copy link
Contributor Author

laogao commented May 4, 2023

The core problem, I think, is with RequiredValidator from reactive_forms, which only marks null values and empty strings as errors, and would happily accept empty lists and maps. I've filed an issue over there joanpablo/reactive_forms#377 . Until that gets resolved, we could have a workaround by leveraging a custom validator.

A PR is underway that provides this workaround. Next I'll see what to do with issue #33.

@laogao
Copy link
Contributor Author

laogao commented May 9, 2023

Currently the isRequired for checkbox element is effective in the sense that it will prevent the containing form from being submitted if the value is empty. Yet there isn't any errorText being displayed. The problem is likely due to the difference between standalone reactive form widgets and arrays of widgets. Maybe there is a way to wire up a errorText at the question level that is properly propagated by validators?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants