From e2c91849fcd70d3bc14d006806f78a179f8573f2 Mon Sep 17 00:00:00 2001 From: ido Date: Tue, 26 Dec 2023 21:29:23 +0200 Subject: [PATCH] fix: default bind --- .../src/components-control/form-utils/bind-form.ts | 13 ++++++++----- packages/forms/src/components/form/BindForm.astro | 5 +++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/forms/src/components-control/form-utils/bind-form.ts b/packages/forms/src/components-control/form-utils/bind-form.ts index 9a47c0f..bae6682 100644 --- a/packages/forms/src/components-control/form-utils/bind-form.ts +++ b/packages/forms/src/components-control/form-utils/bind-form.ts @@ -30,16 +30,19 @@ export class BindForm { return this._plugins.find(x => x.constructor.name == name); } - finishFormValidation() { + defaults() { + this._defaults && Object.assign(this, this._defaults); + } + + /** + * @internal + */ + __finishFormValidation() { for (const plugin of this._plugins) { plugin.createValidation(); } } - defaults() { - this._defaults && Object.assign(this, this._defaults); - } - /** * @internal */ diff --git a/packages/forms/src/components/form/BindForm.astro b/packages/forms/src/components/form/BindForm.astro index 9e8dc06..f86d6f1 100644 --- a/packages/forms/src/components/form/BindForm.astro +++ b/packages/forms/src/components/form/BindForm.astro @@ -2,6 +2,7 @@ import {asyncContext} from '@astro-utils/context'; import getContext from '@astro-utils/context'; import ViewStateManager from '../../components-control/form-utils/view-state.js'; +import Bind from '../../components-control/form-utils/bind-form.js'; export interface Props { bind?: any; @@ -9,14 +10,14 @@ export interface Props { } const {viewStates} = getContext(Astro, '@astro-utils/forms'); -const {bind} = Astro.props; +const {bind = Bind()} = Astro.props; const context = {executeAfter: [], method: Astro.request.method, bind, tempBindValues: {}, elementsState: {}}; const viewState = new ViewStateManager(bind, context.elementsState, Astro, viewStates.counter++); await viewState.loadState(); let htmlSolt = await asyncContext(() => Astro.slots.render('default'), Astro, {name: '@astro-utils/forms', context}); -bind?.finishFormValidation(); +bind.__finishFormValidation(); for (const func of context.executeAfter) { await (func as any)(); }