Rethink input type handling
wesharper opened this issue · 1 comments
I had an issue with number inputs and ran across #41. While coercion is possible on the zod side, it's not well documented within Formsnap and it feels strange. A potential solution could be to use proxies based on an input's type
attribute. For instance, <Form.Input type="number" />
would add a number proxy with sensible defaults.
This would have the added benefit of gracefully being able to handle other types like file
, date
, etc.
This will be improved by #131.
The plan at the moment is to get rid of the Input
components and just provide attributes for them via slot props from the field.
Something along these lines:
<form use:form.enhance method="POST">
<Form.Field {form} name="firstName" let:attrs>
<Form.Label>First Name</Form.Label>
<input {...attrs} bind:value={$theForm.name} />
<Form.Description>Enter your first name</Form.Description>
<Form.Validation />
</Form.Field>
</form>
The superForm
instance would be created by you and you'd have greater control over some of the things I originally thought were a good idea to abstract away.