Releases: svecosystem/formsnap
Releases · svecosystem/formsnap
v0.1.0
v0.0.9
v0.0.8
v0.0.7
v0.0.6
v0.0.5
v0.0.4
v0.0.3
Patch Changes
-
0801f7d: Add the
handlers
object containing the event handler helpers as well as thesetValue
helper function to thegetFormField
return object. -
748f8e8: #### Add a
getFormField
helper functionThe
getFormField
helper function must be called upon component initialization and provides some useful stores, actions, etc. when composing your own forms.
For example, if I wanted to create a reusableForm.Label
with conditional styles applied to it depending on the error state of the field, I could do something like this:<!-- CustomLabel.svelte --> <script lang="ts"> import { Form, getFormField } from "formsnap"; const { errors } = getFormField(); </script> <Form.Label class={$errors ? "text-red-500" : "text-gray-800"}> <slot /> </Form.Label>
It returns the following type:
export type FormFieldContext = { name: string; ids: { input: string; description: string; validation: string; }; errors: Writable<string[] | undefined>; value: Writable<unknown>; hasDescription: Writable<boolean>; hasValidation: Writable<boolean>; attrStore: AttrStore; actions: ActionsObject; };