File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments