Skip to content

Commit

Permalink
expose helper.formContext
Browse files Browse the repository at this point in the history
  • Loading branch information
staff0rd committed Mar 30, 2023
1 parent b917a7c commit 8c66570
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-ears-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@makerx/forms-core': minor
---

Expose helper.formContext
4 changes: 2 additions & 2 deletions packages/core/src/components/ValidatedFormFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const ValidatedFormFactory =
TSchema extends Record<string, unknown>,
K extends FormFieldHelperBase<TSchema>
>(
formFieldHelperFactory: new () => K
formFieldHelperFactory: new (formContext: UseFormReturn<TSchema>) => K
) =>
({
className,
Expand All @@ -65,7 +65,7 @@ export const ValidatedFormFactory =
onSubmit={onSubmit && formContext.handleSubmit(onSubmit)}
>
{typeof children === 'function'
? children(new formFieldHelperFactory())
? children(new formFieldHelperFactory(formContext))
: children}
</form>
</FormProvider>
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/util/FormFieldHelperBase.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { UseFormReturn } from 'react-hook-form';

export class FormFieldHelperBase<TSchema extends Record<string, any>> {
private readonly fieldPrefix: string;
constructor({ fieldPrefix }: { fieldPrefix?: string } = {}) {
constructor(
public formContext: UseFormReturn<TSchema>,
{ fieldPrefix }: { fieldPrefix?: string } = {}
) {
this.fieldPrefix = fieldPrefix ? `${fieldPrefix}.` : '';
}

Expand Down

0 comments on commit 8c66570

Please sign in to comment.