Skip to content

Commit

Permalink
fix(input): readonly state
Browse files Browse the repository at this point in the history
  • Loading branch information
ido-pluto committed May 20, 2024
1 parent 85164e2 commit cd1ec68
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions examples/simple-form/src/pages/state-check.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -16,7 +15,7 @@ function onSubmit() {

<Layout title='Test Select'>
<BindForm bind={bind} key='page'>
{bind.num}
{bind.num?.map((value, index) => <BInput name={`num[${index}]`} placeholder={value} />)}
<BButton whenFormOK onClick={onSubmit}>Submit</BButton>
</BindForm>
</Layout>
6 changes: 3 additions & 3 deletions packages/forms/src/components-control/input-parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>) {
const { value, name, readonly } = astro.props;
if (readonly) {
return value;
return getProperty(bind, name, value);
}

return await getFormValue(astro.request, bindId + name);
Expand All @@ -49,7 +49,7 @@ export async function getInputValue(astro: AstroGlobal, bindId: string) {
export async function validateFormInput(astro: AstroGlobal, bind: BindForm<any>, 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
Expand Down

0 comments on commit cd1ec68

Please sign in to comment.