Skip to content

Commit

Permalink
Fix placeholder on text inputs (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergue1 authored May 30, 2024
1 parent eb51d74 commit 57815a7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions demo/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class BigModel(BaseModel):
None, description='This field is not required, it must start with a capital letter if provided'
)
info: Annotated[str | None, Textarea(rows=5)] = Field(None, description='Optional free text information about you.')
repo: str = Field(json_schema_extra={'placeholder': '{org}/{repo}'}, title='GitHub repository')
profile_pic: Annotated[UploadFile, FormFile(accept='image/*', max_size=16_000)] = Field(
description='Upload a profile picture, must not be more than 16kb'
)
Expand Down
1 change: 1 addition & 0 deletions src/python-fastui/fastui/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def json_schema_field_to_field(
initial=schema.get('default'),
autocomplete=schema.get('autocomplete'),
description=schema.get('description'),
placeholder=schema.get('placeholder'),
)


Expand Down
25 changes: 25 additions & 0 deletions src/python-fastui/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,28 @@ def test_form_description_leakage():
'submitUrl': '/foobar/',
'type': 'ModelForm',
}


class RichForm(BaseModel):
repo: str = Field(json_schema_extra={'placeholder': '{org}/{repo}'}, title='GitHub repository')


def test_form_fields():
m = components.ModelForm(model=RichForm, submit_url='/foobar/')

assert m.model_dump(by_alias=True, exclude_none=True) == {
'formFields': [
{
'htmlType': 'text',
'locked': False,
'name': 'repo',
'placeholder': '{org}/{repo}',
'required': True,
'title': ['GitHub repository'],
'type': 'FormFieldInput',
}
],
'method': 'POST',
'submitUrl': '/foobar/',
'type': 'ModelForm',
}

0 comments on commit 57815a7

Please sign in to comment.