Performance: Fieldsets for form layout
Using fieldsets affects the form's HTML structure and rendering speed by grouping related fields, impacting layout stability and paint time.
<form>
<fieldset>
<legend>Contact Info</legend>
<label for="name">Name</label>
<input id="name" type="text" name="name">
<label for="email">Email</label>
<input id="email" type="email" name="email">
</fieldset>
<fieldset>
<legend>Message</legend>
<label for="message">Message</label>
<textarea id="message" name="message"></textarea>
</fieldset>
</form><form>
<div>
<label>Name</label>
<input type="text" name="name">
</div>
<div>
<label>Email</label>
<input type="email" name="email">
</div>
<div>
<label>Message</label>
<textarea name="message"></textarea>
</div>
</form>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using divs for grouping | More nodes, no semantic grouping | Multiple reflows on style changes | Higher paint cost due to layout shifts | [X] Bad |
| Using fieldsets with legends | Fewer nodes, semantic grouping | Single reflow on style changes | Lower paint cost with stable layout | [OK] Good |
fieldsets in a Django admin form?fieldsets do in Django adminfieldsets are used to group form fields visually under headings to make forms easier to read and organize.fieldsets.fieldsets in a Django admin class?class MyModelAdmin(admin.ModelAdmin):
fieldsets = [
("Personal Info", {"fields": ("first_name", "last_name")}),
("Contact", {"fields": ("email", "phone")})
]fieldsets = [
("Main", ["title", "description"]),
("Details", {"fields": ("date", "location")})
]fieldsets definition correctly achieves this layout?Pass the test and this pattern moves unknown