Here is what my schema:
my data is coming from mysql database, since mysql does not support booleans, the column vegetarian is of type tinyint . Hence the values are 0 or 1
Problem is that with 0 and 1 in data the boolean controls are also rendered as textbox instead of checkbox.
I cannot change mysql data as its coming from data service.
How can i force to render checkbox even if data consists of 0 or 1?
[original thread by kashifxs]
Hi @xs-kashif, I can’t reproduce the described issue. The type of input which is shown depends on the type defined in the JSON schema. So if the type is
boolean we’ll definitely render a checkbox. As
1 are also compatible with
boolean the checked state of the checkbox will also be correct. However once the user changes the state of the checkbox, the data will be transformed to a real boolean, i.e.
false. If you want to keep using0
and1` in your data instead I would either recommend to implement a custom renderer or transforming the data once before sending it back to your database.
We also offer to render JSON Forms without any JSON schema and ui schema only based on your data. In these cases we try to infer the JSON schema from the provided data object. There we would encounter the
0 property and assume that this is a
number input and therefore don’t render a checkbox. So please make sure that you actually provide your JSON Schema to JSON Forms If you still encounter problems, it would be great if you could share your code if possible or showcase a minimal example which repdroduces the behavior.