iway1 / react-ts-form

https://react-ts-form.com
MIT License
2.01k stars 35 forks source link

Support For Unique Enums #10

Closed iway1 closed 1 year ago

iway1 commented 1 year ago

Right now it isn't possible to have a unique enum field that works in any useful way.

I think the only way to implement this would be creating a new function specifically for creating unique enum fields, something like:

const RadioSchema = createUniqueEnumField('id');

const MyForm = z.object({
  radio: MyUniqueEnum.enum(["one", "two"])
})

Needs to be able to pass in options at the form level and only be passed to the mapping once per field component type.

iway1 commented 1 year ago

Alternatively, might remove the enum values feature altogether. Seems to be causing a lot of confusion and may be a footgun, even though it sounds really cool on paper.

Anything that's doable with an enum is doable with a string field, and with string fields there's no need for an expanded API and it covers varied use cases more easily (IE fetching dynamic drop down values from server is impossible via enum, and it's clunky to have both enums and strings map to a component).

scamden commented 1 year ago

wait could you explain more about this decision? i would definitely want to define the possible options in the schema not in the component usage..

tonyxiao commented 1 year ago

Same situation here. We have a lot of enums in codebase so it seems that the alternative would be to manually pass their options over when rendering a form?