react-querybuilder/react-querybuilder

radio as boolean (0, 1) and parseNumbers

oleg-andreyev opened this issue · 4 comments

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

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))
                    }
                }}
            />
        );
    }

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?

@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.

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.