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

radio as boolean (0, 1) and parseNumbers #622

Open
oleg-andreyev opened this issue Dec 29, 2023 · 4 comments
Open

radio as boolean (0, 1) and parseNumbers #622

oleg-andreyev opened this issue Dec 29, 2023 · 4 comments

Comments

@oleg-andreyev
Copy link

oleg-andreyev commented Dec 29, 2023

Right now experiencing issue with radio element, which holds boolean (0, 1).

image
image
image
image

As soon I save and render components once again I see
image
and non-values are selected
image


UPD

Noticed that values name is string, that's why it cannot match.

image
image

but as soon as change type to int, types are swapped in value
image


initial load
image
as soon I click on radio
image

@oleg-andreyev
Copy link
Author

atm applied following workaround:

    if (props.type === 'radio') {
        return (
            <ValueEditor
                {...props}
                handleOnChange={(v) => {
                    let valuesType = typeof props.values[0].name;
                    let valueType = typeof v;

                    if (valueType !== valuesType && valuesType === 'number') {
                        props.handleOnChange(parseInt(v))
                    }
                }}
            />
        );
    }

@jakeboone02
Copy link
Member

Thanks for the report. I think your issue might be more with the behavior of native HTML <input> elements, which always report their value as a string, than RQB. What would you propose as a workaround/fix?

@oleg-andreyev
Copy link
Author

@jakeboone02 I've added a code-snippet here #622 (comment), I see that we'll see to compare values and value, if values has Int, then value should be casted to Int, and vice-versa.

@jakeboone02
Copy link
Member

Yeah, I saw that but didn't consider it might be the actual solution. Want to submit a PR with that change while I think it over (code is here)? An additional test (radio tests here) will probably be necessary to maintain 100% coverage.

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

No branches or pull requests

2 participants