Skip to content

Commit 6cadefa

Browse files
committed
Fix form constraints, take 2
1 parent ce65758 commit 6cadefa

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ interface FormFieldInputProps extends BaseFormFieldProps {
3030
type: 'FormFieldInput'
3131
htmlType: 'text' | 'date' | 'datetime-local' | 'time' | 'email' | 'url' | 'number' | 'password'
3232
initial?: string | number
33+
/** @TJS-type integer */
3334
maxLength?: number
35+
/** @TJS-type integer */
3436
minLength?: number
3537
ge?: number
3638
le?: number

src/python-fastui/fastui/components/forms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class FormFieldInput(BaseFormField):
3434
placeholder: _t.Union[str, None] = None
3535
max_length: _t.Union[int, None] = pydantic.Field(default=None, serialization_alias='maxLength')
3636
min_length: _t.Union[int, None] = pydantic.Field(default=None, serialization_alias='minLength')
37-
ge: _t.Union[int, float, None] = None
38-
le: _t.Union[int, float, None] = None
39-
multiple_of: _t.Union[int, float, None] = pydantic.Field(default=None, serialization_alias='multipleOf')
37+
ge: _t.Union[float, None] = None
38+
le: _t.Union[float, None] = None
39+
multiple_of: _t.Union[float, None] = pydantic.Field(default=None, serialization_alias='multipleOf')
4040
type: _t.Literal['FormFieldInput'] = 'FormFieldInput'
4141

4242

src/python-fastui/fastui/json_schema.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ class JsonSchemaString(JsonSchemaBase):
4646
type: _ta.Required[_t.Literal['string']]
4747
default: str
4848
format: _t.Literal['date', 'date-time', 'time', 'email', 'uri', 'uuid', 'password']
49-
maxLength: int
50-
minLength: int
5149

5250

5351
class JsonSchemaStringEnum(JsonSchemaBase, total=False):
@@ -63,8 +61,6 @@ class JsonSchemaStringSearch(JsonSchemaBase, total=False):
6361
search_url: _ta.Required[str]
6462
placeholder: str
6563
initial: SelectOption
66-
maxLength: int
67-
minLength: int
6864

6965

7066
class JsonSchemaFile(JsonSchemaBase, total=False):
@@ -87,6 +83,8 @@ class JsonSchemaInt(JsonSchemaBase, total=False):
8783
maximum: int
8884
exclusiveMaximum: int
8985
multipleOf: int
86+
maxLength: int
87+
minLength: int
9088

9189

9290
class JsonSchemaNumber(JsonSchemaBase, total=False):

src/python-fastui/tests/react-fastui-json-schema.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,16 +473,31 @@
473473
"error": {
474474
"type": "string"
475475
},
476+
"ge": {
477+
"type": "number"
478+
},
476479
"htmlType": {
477480
"enum": ["date", "datetime-local", "email", "number", "password", "text", "time", "url"],
478481
"type": "string"
479482
},
480483
"initial": {
481484
"type": ["string", "number"]
482485
},
486+
"le": {
487+
"type": "number"
488+
},
483489
"locked": {
484490
"type": "boolean"
485491
},
492+
"maxLength": {
493+
"type": "integer"
494+
},
495+
"minLength": {
496+
"type": "integer"
497+
},
498+
"multipleOf": {
499+
"type": "number"
500+
},
486501
"name": {
487502
"type": "string"
488503
},

src/python-fastui/tests/test_forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async def form(self):
3131

3232
def test_simple_form_fields():
3333
m = components.ModelForm[SimpleForm](submit_url='/foobar/')
34-
print(m.model_dump(by_alias=True, exclude_none=True))
34+
3535
assert m.model_dump(by_alias=True, exclude_none=True) == {
3636
'submitUrl': '/foobar/',
3737
'method': 'POST',

0 commit comments

Comments
 (0)