vazco / uniforms

A React library for building forms from any schema.
https://uniforms.tools
MIT License
1.95k stars 240 forks source link

Support indeterminate checkbox #1333

Closed dwidge closed 5 months ago

dwidge commented 5 months ago

request

Show an indeterminate checkbox when its value is undefined?

When a boolean value is optional and was never clicked by the user, it submits undefined. If the user clicks the checkbox twice it submits false. If they click a third time, can it become undefined again?

notes

https://css-tricks.com/indeterminate-checkboxes/

https://www.w3schools.com/jsref/prop_checkbox_indeterminate.asp A checkbox cannot be set to indeterminate state by an HTML attribute - it must be set by a JavaScript.

document.getElementById("myCheck").indeterminate = true;

packages

import ZodBridge from "uniforms-bridge-zod";
import { AutoForm } from "uniforms-mui";
import { AutoForm } from "uniforms-unstyled";
mariusrak commented 5 months ago

You can, and probably should, implement it by yourself outside of uniforms, since it is not standard behavior. You can simply create custom fields https://uniforms.tools/docs/examples-custom-fields/

piotrpospiech commented 5 months ago

Hi @dwidge, as @mariusrak wrote, creating a custom field for such a scenario will be the best approach.