Skip to content

Commit

Permalink
feat: support locked fields
Browse files Browse the repository at this point in the history
  • Loading branch information
elio2t committed Oct 23, 2024
1 parent 5d9d604 commit 3a23b5c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
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

0 comments on commit 3a23b5c

Please sign in to comment.