Fieldset is a container for grouping related form elements. It includes fieldset-legend as a title and label as a description.
Base Fieldset
Exported source
fieldset = SingleValueFactory("fieldset", "Base fieldset component for the fieldset container") # Base fieldset componentlabel = SingleValueFactory("label", "Base label component for inputs") # Base label componentfieldset_legend = SingleValueFactory("fieldset-legend", "fieldset legend part for the title of the fieldset") # fieldset legend part
Test basic fieldset with legend and label from daisyUI v5 documentation.
Exported source
def test_fieldset_basic_fasthtml_examples():"""Test basic fieldset with legend and label from daisyUI v5 documentation."""from fasthtml.common import Fieldset, Legend, Input, Pfrom cjm_fasthtml_daisyui.components.data_input.text_input import text_input# Fieldset with legend and label basic_fieldset = Fieldset( Legend("Page title", cls=str(fieldset_legend)), Input(type="text", placeholder="My awesome page", cls=str(text_input)), P("You can edit page title later on from settings", cls=str(label)), cls=str(fieldset) )# Verify structureassert basic_fieldset.tag =="fieldset"assert basic_fieldset.attrs['class'] =="fieldset"# Verify legend legend_element = basic_fieldset.children[0]assert legend_element.tag =="legend"assert legend_element.attrs['class'] =="fieldset-legend"assert legend_element.children[0] =="Page title"# Verify input input_element = basic_fieldset.children[1]assert input_element.tag =="input"assert input_element.attrs['type'] =="text"assert input_element.attrs['placeholder'] =="My awesome page"assert input_element.attrs['class'] =="input"# Verify label label_element = basic_fieldset.children[2]assert label_element.tag =="p"assert label_element.attrs['class'] =="label"assert label_element.children[0] =="You can edit page title later on from settings"return basic_fieldset# Run the teststest_fieldset_basic_fasthtml_examples()
<fieldset class="fieldset"><legend class="fieldset-legend">Page title</legend><input type="text" placeholder="My awesome page" class="input"><p class="label">You can edit page title later on from settings</p></fieldset>
Test fieldset with background and border from daisyUI v5 documentation.
Exported source
def test_fieldset_with_background_fasthtml_examples():"""Test fieldset with background and border from daisyUI v5 documentation."""from fasthtml.common import Fieldset, Legend, Input, Pfrom cjm_fasthtml_tailwind.utilities.sizing import wfrom cjm_fasthtml_tailwind.utilities.borders import borderfrom cjm_fasthtml_tailwind.utilities.spacing import pfrom cjm_fasthtml_daisyui.utilities.semantic_colors import bg_dui, border_duifrom cjm_fasthtml_daisyui.utilities.border_radius import border_radiusfrom cjm_fasthtml_daisyui.components.data_input.text_input import text_input# Fieldset with background and border styled_fieldset = Fieldset( Legend("Page title", cls=str(fieldset_legend)), Input(type="text", placeholder="My awesome page", cls=str(text_input)), P("You can edit page title later on from settings", cls=str(label)), cls=combine_classes( fieldset, bg_dui.base_200, border_dui.base_300, border_radius.box, w.xs, border, p._4 ) )# Verify structureassert styled_fieldset.tag =="fieldset"assert"fieldset"in styled_fieldset.attrs['class']assert"bg-base-200"in styled_fieldset.attrs['class']assert"border-base-300"in styled_fieldset.attrs['class']assert"rounded-box"in styled_fieldset.attrs['class']assert"w-xs"in styled_fieldset.attrs['class']assert"border"in styled_fieldset.attrs['class']assert"p-4"in styled_fieldset.attrs['class']# Verify legend legend_element = styled_fieldset.children[0]assert legend_element.tag =="legend"assert legend_element.attrs['class'] =="fieldset-legend"assert legend_element.children[0] =="Page title"# Verify input input_element = styled_fieldset.children[1]assert input_element.tag =="input"assert input_element.attrs['type'] =="text"assert input_element.attrs['placeholder'] =="My awesome page"assert input_element.attrs['class'] =="input"# Verify label label_element = styled_fieldset.children[2]assert label_element.tag =="p"assert label_element.attrs['class'] =="label"assert label_element.children[0] =="You can edit page title later on from settings"return styled_fieldset# Run the teststest_fieldset_with_background_fasthtml_examples()
<fieldset class="fieldset bg-base-200 border-base-300 rounded-box w-xs <cjm_fasthtml_tailwind.utilities.borders.BorderWidthFactory object at 0x7f99fd6a9290> p-4"><legend class="fieldset-legend">Page title</legend><input type="text" placeholder="My awesome page" class="input"><p class="label">You can edit page title later on from settings</p></fieldset>