Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support locked FormFields #362

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion demo/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations as _annotations

import enum
import uuid
from collections import defaultdict
from datetime import date
from typing import Annotated, Literal, TypeAlias
Expand Down Expand Up @@ -164,11 +165,15 @@ class BigModel(BaseModel):
None, title='Is human', description='Are you human?', json_schema_extra={'mode': 'switch'}
)
size: SizeModel

position: tuple[
Annotated[int, Field(description='X Coordinate')],
Annotated[int, Field(description='Y Coordinate')],
]
auto_generated_id: str = Field(
str(uuid.uuid4()),
description='This field is locked',
json_schema_extra={'locked': True},
)

@field_validator('name')
def name_validator(cls, v: str | None) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/npm-fastui/src/components/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const FormComp: FC<Form | ModelForm> = (props) => {
const f = {
...formField,
error: fieldErrors[formField.name],
locked,
locked: locked || formField.locked,
displayMode,
onChange,
} as FormFieldProps
Expand Down
6 changes: 6 additions & 0 deletions src/python-fastui/fastui/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def json_schema_field_to_field(
name=name,
title=title,
required=required,
locked=schema.get('locked', False),
initial=schema.get('default'),
description=schema.get('description'),
mode=schema.get('mode', 'checkbox'),
Expand All @@ -194,6 +195,7 @@ def json_schema_field_to_field(
title=title,
html_type=input_html_type(schema),
required=required,
locked=schema.get('locked', False),
initial=schema.get('default'),
autocomplete=schema.get('autocomplete'),
description=schema.get('description'),
Expand Down Expand Up @@ -244,6 +246,7 @@ def special_string_field(
name=name,
title=title,
required=required,
locked=schema.get('locked', False),
multiple=multiple,
accept=schema.get('accept'),
description=schema.get('description'),
Expand All @@ -253,6 +256,7 @@ def special_string_field(
name=name,
title=title,
required=required,
locked=schema.get('locked', False),
rows=schema.get('rows'),
cols=schema.get('cols'),
placeholder=schema.get('placeholder'),
Expand All @@ -267,6 +271,7 @@ def special_string_field(
title=title,
placeholder=schema.get('placeholder'),
required=required,
locked=schema.get('locked', False),
multiple=multiple,
options=[SelectOption(value=v, label=enum_labels.get(v) or as_title(v)) for v in enum],
initial=schema.get('default'),
Expand All @@ -280,6 +285,7 @@ def special_string_field(
title=title,
placeholder=schema.get('placeholder'),
required=required,
locked=schema.get('locked', False),
multiple=multiple,
initial=schema.get('initial'),
description=schema.get('description'),
Expand Down