You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Export useFieldState, splitFieldProps and usePublishField for custom fields #23
javaabu/block-editor ships a React field for @javaabu/forms (<BlockEditorField name="body" />, Javaabu/block-editor#8). It should behave like the built-in fields, so it needs the hooks Wysiwyg uses, and they aren't exported from @javaabu/forms:
useFieldState(name, initial, options): reads and writes the form's external store (Inertia useForm() data), returns to the starting value on reset, and clears the field's errors when edited.
splitFieldProps(props): separates FieldProps from control props.
usePublishField(entry): publishes the value so ConditionalWrapper / useWatchField can react to it.
Request: export these three (and their option types) from the package root, documented as the API for custom fields in other packages. A short "Custom fields" docs page with a Wysiwyg-like example would help other package agents too.
Until then: block-editor's field keeps its own state and posts a hidden input. With useForm(), apps bind it by hand (value={form.data.body} onChange={(v) => form.setData("body", v)}), and reset and ConditionalWrapper don't see it.
Exported from @javaabu/forms: useFieldState, splitFieldProps, usePublishField, and the types FieldStateOptions, UseFieldOptions, FieldEntry, FieldKind. With useField and useFieldValue (already exported), a field from another package gets the same behaviour as the built-in ones: useForm() data, resetOnSuccess, ConditionalWrapper / useWatchField, and errors that clear on edit.
Docs: docs/advanced-usage/custom-fields.md (a Wysiwyg-like example plus a checklist: hidden input for native submits, ARIA on non-native controls, controlled, toStore / fromStore, key, store: false, nested-key errors). It's also in the Boost skill (references/custom-fields.md) and llms.txt.
Tests: src/components/custom-field.test.tsx builds a field with only root imports and covers binding, native submit, errors clearing on edit, ConditionalWrapper, resetOnSuccess and useForm() data.
For BlockEditorField: replace the own state and onChange → clearErrors with useFieldState(name, initial, { toStore: JSON.stringify, fromStore: … }), and add usePublishField. Block-level errors can keep reading useFormState()?.errors.
Activity
Custom field hooks, useTableSelection, Blade icon names
n4ff4h commentedon Nov 5, 2026
Done in 204e616 on
next-gen(PR #19), CI green: https://github.com/Javaabu/react-forms/actions/runs/42055926515Exported from
@javaabu/forms:useFieldState,splitFieldProps,usePublishField, and the typesFieldStateOptions,UseFieldOptions,FieldEntry,FieldKind. WithuseFieldanduseFieldValue(already exported), a field from another package gets the same behaviour as the built-in ones:useForm()data,resetOnSuccess,ConditionalWrapper/useWatchField, and errors that clear on edit.docs/advanced-usage/custom-fields.md(aWysiwyg-like example plus a checklist: hidden input for native submits, ARIA on non-native controls,controlled,toStore/fromStore,key,store: false, nested-key errors). It's also in the Boost skill (references/custom-fields.md) andllms.txt.src/components/custom-field.test.tsxbuilds a field with only root imports and covers binding, native submit, errors clearing on edit,ConditionalWrapper,resetOnSuccessanduseForm()data.For
BlockEditorField: replace the own state andonChange → clearErrorswithuseFieldState(name, initial, { toStore: JSON.stringify, fromStore: … }), and addusePublishField. Block-level errors can keep readinguseFormState()?.errors.