Skip to content

Commit 3a23b5c

Browse files
committed
feat: support locked fields
1 parent 5d9d604 commit 3a23b5c

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

demo/forms.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations as _annotations
22

33
import enum
4+
import uuid
45
from collections import defaultdict
56
from datetime import date
67
from typing import Annotated, Literal, TypeAlias
@@ -164,11 +165,15 @@ class BigModel(BaseModel):
164165
None, title='Is human', description='Are you human?', json_schema_extra={'mode': 'switch'}
165166
)
166167
size: SizeModel
167-
168168
position: tuple[
169169
Annotated[int, Field(description='X Coordinate')],
170170
Annotated[int, Field(description='Y Coordinate')],
171171
]
172+
auto_generated_id: str = Field(
173+
str(uuid.uuid4()),
174+
description='This field is locked',
175+
json_schema_extra={'locked': True},
176+
)
172177

173178
@field_validator('name')
174179
def name_validator(cls, v: str | None) -> str:

src/npm-fastui/src/components/form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export const FormComp: FC<Form | ModelForm> = (props) => {
107107
const f = {
108108
...formField,
109109
error: fieldErrors[formField.name],
110-
locked,
110+
locked: locked || formField.locked,
111111
displayMode,
112112
onChange,
113113
} as FormFieldProps

src/python-fastui/fastui/json_schema.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def json_schema_field_to_field(
182182
name=name,
183183
title=title,
184184
required=required,
185+
locked=schema.get('locked', False),
185186
initial=schema.get('default'),
186187
description=schema.get('description'),
187188
mode=schema.get('mode', 'checkbox'),
@@ -194,6 +195,7 @@ def json_schema_field_to_field(
194195
title=title,
195196
html_type=input_html_type(schema),
196197
required=required,
198+
locked=schema.get('locked', False),
197199
initial=schema.get('default'),
198200
autocomplete=schema.get('autocomplete'),
199201
description=schema.get('description'),
@@ -244,6 +246,7 @@ def special_string_field(
244246
name=name,
245247
title=title,
246248
required=required,
249+
locked=schema.get('locked', False),
247250
multiple=multiple,
248251
accept=schema.get('accept'),
249252
description=schema.get('description'),
@@ -253,6 +256,7 @@ def special_string_field(
253256
name=name,
254257
title=title,
255258
required=required,
259+
locked=schema.get('locked', False),
256260
rows=schema.get('rows'),
257261
cols=schema.get('cols'),
258262
placeholder=schema.get('placeholder'),
@@ -267,6 +271,7 @@ def special_string_field(
267271
title=title,
268272
placeholder=schema.get('placeholder'),
269273
required=required,
274+
locked=schema.get('locked', False),
270275
multiple=multiple,
271276
options=[SelectOption(value=v, label=enum_labels.get(v) or as_title(v)) for v in enum],
272277
initial=schema.get('default'),
@@ -280,6 +285,7 @@ def special_string_field(
280285
title=title,
281286
placeholder=schema.get('placeholder'),
282287
required=required,
288+
locked=schema.get('locked', False),
283289
multiple=multiple,
284290
initial=schema.get('initial'),
285291
description=schema.get('description'),

0 commit comments

Comments
 (0)