Skip to content

Commit da0fefa

Browse files
committed
Fix form constraints, take 2
1 parent 50bb35c commit da0fefa

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' | 'hidden'
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
@@ -32,9 +32,9 @@ class FormFieldInput(BaseFormField):
3232
placeholder: _t.Union[str, None] = None
3333
max_length: _t.Union[int, None] = pydantic.Field(default=None, serialization_alias='maxLength')
3434
min_length: _t.Union[int, None] = pydantic.Field(default=None, serialization_alias='minLength')
35-
ge: _t.Union[int, float, None] = None
36-
le: _t.Union[int, float, None] = None
37-
multiple_of: _t.Union[int, float, None] = pydantic.Field(default=None, serialization_alias='multipleOf')
35+
ge: _t.Union[float, None] = None
36+
le: _t.Union[float, None] = None
37+
multiple_of: _t.Union[float, None] = pydantic.Field(default=None, serialization_alias='multipleOf')
3838
type: _t.Literal['FormFieldInput'] = 'FormFieldInput'
3939

4040

src/python-fastui/fastui/json_schema.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ class JsonSchemaString(JsonSchemaBase):
4949
type: _ta.Required[_t.Literal['string']]
5050
default: str
5151
format: _t.Literal['date', 'date-time', 'time', 'email', 'uri', 'uuid', 'password']
52-
maxLength: int
53-
minLength: int
5452

5553

5654
class JsonSchemaStringEnum(JsonSchemaBase, total=False):
@@ -66,8 +64,6 @@ class JsonSchemaStringSearch(JsonSchemaBase, total=False):
6664
search_url: _ta.Required[str]
6765
placeholder: str
6866
initial: SelectOption
69-
maxLength: int
70-
minLength: int
7167

7268

7369
class JsonSchemaFile(JsonSchemaBase, total=False):
@@ -90,6 +86,8 @@ class JsonSchemaInt(JsonSchemaBase, total=False):
9086
maximum: int
9187
exclusiveMaximum: int
9288
multipleOf: int
89+
maxLength: int
90+
minLength: int
9391

9492

9593
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
@@ -572,16 +572,31 @@
572572
"error": {
573573
"type": "string"
574574
},
575+
"ge": {
576+
"type": "number"
577+
},
575578
"htmlType": {
576579
"enum": ["date", "datetime-local", "email", "hidden", "number", "password", "text", "time", "url"],
577580
"type": "string"
578581
},
579582
"initial": {
580583
"type": ["string", "number"]
581584
},
585+
"le": {
586+
"type": "number"
587+
},
582588
"locked": {
583589
"type": "boolean"
584590
},
591+
"maxLength": {
592+
"type": "integer"
593+
},
594+
"minLength": {
595+
"type": "integer"
596+
},
597+
"multipleOf": {
598+
"type": "number"
599+
},
585600
"name": {
586601
"type": "string"
587602
},

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)