From cd1ec68d1dca6587b06c796963b084bd0594b289 Mon Sep 17 00:00:00 2001 From: ido Date: Mon, 20 May 2024 20:50:41 +0300 Subject: [PATCH] fix(input): readonly state --- examples/simple-form/src/pages/state-check.astro | 7 +++---- packages/forms/src/components-control/input-parse.ts | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/examples/simple-form/src/pages/state-check.astro b/examples/simple-form/src/pages/state-check.astro index 44468c4..24b1d23 100644 --- a/examples/simple-form/src/pages/state-check.astro +++ b/examples/simple-form/src/pages/state-check.astro @@ -5,9 +5,8 @@ import Layout from '../layouts/Layout.astro'; const bind = Bind({}); bind.on.newState = () => { - bind.num = 9; -} - + bind.num = [1, 2, 3, 9]; +}; function onSubmit() { console.log(bind.num); @@ -16,7 +15,7 @@ function onSubmit() { - {bind.num} + {bind.num?.map((value, index) => )} Submit diff --git a/packages/forms/src/components-control/input-parse.ts b/packages/forms/src/components-control/input-parse.ts index fd467e7..1f05ee5 100644 --- a/packages/forms/src/components-control/input-parse.ts +++ b/packages/forms/src/components-control/input-parse.ts @@ -37,10 +37,10 @@ type InputTypes = type ExtendedInputTypes = InputTypes | 'int'; -export async function getInputValue(astro: AstroGlobal, bindId: string) { +export async function getInputValue(astro: AstroGlobal, bindId: string, bind: BindForm) { const { value, name, readonly } = astro.props; if (readonly) { - return value; + return getProperty(bind, name, value); } return await getFormValue(astro.request, bindId + name); @@ -49,7 +49,7 @@ export async function getInputValue(astro: AstroGlobal, bindId: string) { export async function validateFormInput(astro: AstroGlobal, bind: BindForm, bindId: string) { const { type, value: originalValue, minlength, maxlength, pattern, required, name, errorMessage, validate } = astro.props; - const parseValue: any = await getInputValue(astro, bindId); + const parseValue: any = await getInputValue(astro, bindId, bind); const aboutInput = new AboutFormName(bind, name, parseValue, errorMessage); // validate filed exits