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

Boolean option for RadioButtonGroup #294

Open
2 tasks done
smeet2296 opened this issue Jul 30, 2024 · 4 comments
Open
2 tasks done

Boolean option for RadioButtonGroup #294

smeet2296 opened this issue Jul 30, 2024 · 4 comments

Comments

@smeet2296
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

Currently RadioButtonGroup Element supports string and number. But if I want to use a Yes/No radio button which should store true/false its not working.

Example optionsArray : [{"id":true,"value":"Yes"},{"id":false,"value":"No"}]

If for reducing complexity there is a way that the options have string true/false values and then the value gets stored as boolean that would also be fine

Examples 🌈

No response

@dohomi
Copy link
Owner

dohomi commented Jul 30, 2024

any PR is welcome

@smeet2296
Copy link
Author

smeet2296 commented Jul 31, 2024

@dohomi

I found a workaround

For the example optionsArray mentioned above, we can do the following

transform={{
input: (value) => {
return value != null ? value : "";
},
output: (_, value) => {
return value === "true" ? true : value === "false" ? false : "";
},
}}

The only problem is react-hook-form/react-hook-form#2323

For this, we can avoid using required in rule as well as prop and use validate function in the rule instead. We will have to add the asterisk in the label manually.

I wanted to add boolean type inbuilt but then due to the above mentioned git issue, required rule and prop will stop working

@dohomi
Copy link
Owner

dohomi commented Jul 31, 2024

I really think you make yourself too much trouble: either use a checkbox / switch which handle true/false natively or use "0" "1" and just cast the value shortly before you persist it in the database inside your handleSubmit. I am currently loaded with work that I won't spend time on the issue. If you find something usable I am happy to review a PR

@smeet2296
Copy link
Author

Yes we can do that if there is only a form that we are building. But I am building a form configurator and I cannot have such restrictions that a user cannot configure boolean values through it. The above solution works for now.

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