Skip to content

Commit 6631928

Browse files
committed
Add formfield_overrides example. Add label and help props.
1 parent 567ea9f commit 6631928

5 files changed

Lines changed: 143 additions & 16 deletions

File tree

docs/build.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ def read_cls_docstring(cls):
4242

4343
def get_versions():
4444
return [
45+
{
46+
"version": "0.3.2",
47+
"changes": [
48+
"Add formfield_overrides example. Add label and help props.",
49+
],
50+
},
4551
{
4652
"version": "0.3.1",
4753
"changes": [
@@ -588,6 +594,23 @@ def get_page_context(page_url):
588594
"type": "alert-warning",
589595
"content": "See <a href='https://ant.design/components/overview' target='_blank'>antd components</a> for more details (e.g. how they look).",
590596
},
597+
{
598+
"type": "text",
599+
"content": "Use <code>formfield_overrides</code> to customize widget props per field. You can set <code>label</code> for a custom field label and <code>help</code> for description text below the field:",
600+
},
601+
{
602+
"type": "code-python",
603+
"content": '''formfield_overrides = {
604+
"username": (
605+
WidgetType.SlugInput,
606+
{
607+
"required": True,
608+
"label": "Custom label",
609+
"help": "Detailed description of the field",
610+
},
611+
),
612+
}''',
613+
},
591614
]
592615
# inlines
593616
case "#registering-inlines":

docs/index.html

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ <h4 class="title">FastAdmin</h4>
196196

197197
<ul class="nav flex-column">
198198

199+
<li class="nav-item">
200+
<a class="nav-link" href="#v0_3_2">v0.3.2</a>
201+
</li>
202+
203+
<li class="nav-item">
204+
<a class="nav-link" href="#v0_3_1">v0.3.1</a>
205+
</li>
206+
199207
<li class="nav-item">
200208
<a class="nav-link" href="#v0_3_0">v0.3.0</a>
201209
</li>
@@ -307,7 +315,7 @@ <h1>FastAdmin | Documentation</h1>
307315
<div class="row">
308316
<div class="col-sm-6 col-lg-4">
309317
<ul class="list-unstyled">
310-
<li><strong>Version:</strong> 0.3.0</li>
318+
<li><strong>Version:</strong> 0.3.2</li>
311319
<li>
312320
<strong>Author:</strong>
313321
<a href="mailto:[email protected]" target="_blank">
@@ -324,7 +332,7 @@ <h1>FastAdmin | Documentation</h1>
324332
</li>
325333
<li>
326334
<strong>Updated:</strong>
327-
18 February 2026
335+
19 February 2026
328336
</li>
329337
</ul>
330338
</div>
@@ -2799,6 +2807,53 @@ <h3>Form Field Types</h3>
27992807

28002808

28012809

2810+
2811+
<p class="text-4">
2812+
Use <code>formfield_overrides</code> to customize widget props per field. You can set <code>label</code> for a custom field label and <code>help</code> for description text below the field:
2813+
</p>
2814+
2815+
2816+
2817+
2818+
2819+
2820+
2821+
2822+
2823+
2824+
2825+
2826+
2827+
2828+
2829+
2830+
2831+
2832+
2833+
2834+
2835+
2836+
2837+
2838+
2839+
<pre>
2840+
<code class="language-python">
2841+
formfield_overrides = {
2842+
"username": (
2843+
WidgetType.SlugInput,
2844+
{
2845+
"required": True,
2846+
"label": "Custom label",
2847+
"help": "Detailed description of the field",
2848+
},
2849+
),
2850+
}
2851+
</code>
2852+
</pre>
2853+
2854+
2855+
2856+
28022857
</section>
28032858

28042859

@@ -3163,6 +3218,56 @@ <h2>Changelog</h2>
31633218

31643219

31653220

3221+
<section id="v0_3_2">
3222+
<h3>v0.3.2</h3>
3223+
3224+
3225+
3226+
<p class="text-4">
3227+
Add formfield_overrides example. Add label and help props.
3228+
</p>
3229+
3230+
3231+
3232+
3233+
3234+
3235+
3236+
3237+
3238+
3239+
3240+
3241+
3242+
3243+
</section>
3244+
3245+
3246+
<section id="v0_3_1">
3247+
<h3>v0.3.1</h3>
3248+
3249+
3250+
3251+
<p class="text-4">
3252+
Fix sqlalchemy required fields. Fix CI.
3253+
</p>
3254+
3255+
3256+
3257+
3258+
3259+
3260+
3261+
3262+
3263+
3264+
3265+
3266+
3267+
3268+
</section>
3269+
3270+
31663271
<section id="v0_3_0">
31673272
<h3>v0.3.0</h3>
31683273

examples/fastapi_sqlalchemy/example.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ class UserModelAdmin(SqlAlchemyModelAdmin):
2020
list_filter = ("id", "username", "is_superuser")
2121
search_fields = ("username",)
2222
formfield_overrides = { # noqa: RUF012
23-
"username": (WidgetType.SlugInput, {"required": True,
24-
# Changing the field label to a custom option
25-
# "label": "Custom label",
26-
# Adding a small text below the field to better understand the purpose of the field
27-
# "help": "Detailed description of the field"
28-
}),
23+
"username": (WidgetType.SlugInput, {"required": True}),
2924
"password": (WidgetType.PasswordInput, {"passwordModalForm": True}),
3025
"avatar_url": (
3126
WidgetType.Upload,

frontend/src/components/form-container/index.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Col, Collapse, Divider, Form, Row, Typography} from "antd";
1+
import { Col, Collapse, Divider, Form, Row, Typography } from "antd";
22
import type React from "react";
33
import { useCallback, useEffect, useState } from "react";
44
import { useTranslation } from "react-i18next";
@@ -103,9 +103,10 @@ export const FormContainer: React.FC<IFormContainer> = ({
103103
key={field.name}
104104
name={field.name}
105105
label={
106-
getConf(field).form_widget_props?.label
107-
? getConf(field)?.form_widget_props?.label
108-
: getTitleFromFieldName(field.name)}
106+
getConf(field).form_widget_props?.label
107+
? getConf(field)?.form_widget_props?.label
108+
: getTitleFromFieldName(field.name)
109+
}
109110
rules={
110111
[
111112
...(getConf(field).required
@@ -170,11 +171,14 @@ export const FormContainer: React.FC<IFormContainer> = ({
170171
}
171172
>
172173
{getWidget(getConf(field))}
173-
{getConf(field).form_widget_props?.help &&
174-
<Typography.Text type={"secondary"} style={{marginTop: ".35rem", display: "flex"}}>
174+
{getConf(field).form_widget_props?.help && (
175+
<Typography.Text
176+
type={"secondary"}
177+
style={{ marginTop: ".35rem", display: "flex" }}
178+
>
175179
{getConf(field).form_widget_props?.help}
176180
</Typography.Text>
177-
}
181+
)}
178182
</Form.Item>
179183
));
180184
},

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "fastadmin"
3-
version = "0.3.1"
3+
version = "0.3.2"
44
description = "FastAdmin is an easy-to-use Admin Dashboard App for FastAPI/Flask/Django inspired by Django Admin."
55
authors = ["Seva D <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)