Skip to content

Commit 57815a7

Browse files
authored
Fix placeholder on text inputs (#304)
1 parent eb51d74 commit 57815a7

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

demo/forms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class BigModel(BaseModel):
144144
None, description='This field is not required, it must start with a capital letter if provided'
145145
)
146146
info: Annotated[str | None, Textarea(rows=5)] = Field(None, description='Optional free text information about you.')
147+
repo: str = Field(json_schema_extra={'placeholder': '{org}/{repo}'}, title='GitHub repository')
147148
profile_pic: Annotated[UploadFile, FormFile(accept='image/*', max_size=16_000)] = Field(
148149
description='Upload a profile picture, must not be more than 16kb'
149150
)

src/python-fastui/fastui/json_schema.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ def json_schema_field_to_field(
197197
initial=schema.get('default'),
198198
autocomplete=schema.get('autocomplete'),
199199
description=schema.get('description'),
200+
placeholder=schema.get('placeholder'),
200201
)
201202

202203

src/python-fastui/tests/test_forms.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,3 +522,28 @@ def test_form_description_leakage():
522522
'submitUrl': '/foobar/',
523523
'type': 'ModelForm',
524524
}
525+
526+
527+
class RichForm(BaseModel):
528+
repo: str = Field(json_schema_extra={'placeholder': '{org}/{repo}'}, title='GitHub repository')
529+
530+
531+
def test_form_fields():
532+
m = components.ModelForm(model=RichForm, submit_url='/foobar/')
533+
534+
assert m.model_dump(by_alias=True, exclude_none=True) == {
535+
'formFields': [
536+
{
537+
'htmlType': 'text',
538+
'locked': False,
539+
'name': 'repo',
540+
'placeholder': '{org}/{repo}',
541+
'required': True,
542+
'title': ['GitHub repository'],
543+
'type': 'FormFieldInput',
544+
}
545+
],
546+
'method': 'POST',
547+
'submitUrl': '/foobar/',
548+
'type': 'ModelForm',
549+
}

0 commit comments

Comments
 (0)