Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Edit this page
Toggle table of contents sidebar

# Form containers

References

  - Foundation 6 fieldset;

  - Foundation 6 Accordion;

  - Foundation 6 Tabs;

class crispy_forms_foundation.layout.containers.Fieldset(legend, *fields, css_class=None, css_id=None, template=None, **kwargs)

  Bases: `Fieldset`

  It wraps fields in a `<fieldset>`:

      Fieldset("Text for the legend",
          'form_field_1',
          'form_field_2'
      )

  The first parameter is the text for the fieldset legend. This text is context aware, so you can do things like :

      Fieldset("Data for {{ user.username }}",
          'form_field_1',
          'form_field_2'
      )

class crispy_forms_foundation.layout.containers.Container(name, *fields, css_id=None, css_class=None, template=None, active=None, **kwargs)

  Bases: `Container`

  Overrides original Container element to get the “active” classname from Class attribute `active_css_class` so it’s compatible with Foundation 5 and 6.

class crispy_forms_foundation.layout.containers.ContainerHolder(*fields, css_id=None, css_class=None, template=None, **kwargs)

  Bases: `ContainerHolder`

class crispy_forms_foundation.layout.containers.TabHolder(*fields, css_id=None, css_class=None, template=None, **kwargs)

  Bases: `TabHolder`

  Tabs holder object to wrap Tab item objects in a container:

      TabHolder(
          TabItem('My tab 1', 'form_field_1', 'form_field_2'),
          TabItem('My tab 2', 'form_field_3')
      )

  `TabHolder` direct children should allways be a `TabItem` layout item.

  A random id is builded for the tab holder if you don’t define it using `css_id` argument.

  The first `TabItem` containing a field error will be marked as active if any, else this will be just the first `TabItem`.

  render(form, context, template_pack=<SimpleLazyObject: <function get_template_pack>>)

    Re-implement almost the same code from crispy_forms but passing `form` instance to item `render_link` method.

class crispy_forms_foundation.layout.containers.VerticalTabHolder(*fields, css_id=None, css_class=None, template=None, **kwargs)

  Bases: `TabHolder`

  VerticalTabHolder appends vertical class to TabHolder container

class crispy_forms_foundation.layout.containers.TabItem(name, *fields, css_id=None, css_class=None, template=None, active=None, **kwargs)

  Bases: `Container`

  Tab item object. It wraps fields in a div whose default class is “tabs” and takes a name as first argument.

  Tab item is also responsible of building its associated tab link with its `render_link` using the `link_template` attribute.

  Example:

      TabItem('My tab', 'form_field_1', 'form_field_2', 'form_field_3')

  `TabItem` layout item has no real utility out of a `TabHolder`.

  has_errors(form)

    Find tab fields listed as invalid

  render_link(form, template_pack=<SimpleLazyObject: <function get_template_pack>>, **kwargs)

    Render the link for the tab-pane. It must be called after render so `css_class` is updated with `active` class name if needed.

class crispy_forms_foundation.layout.containers.AccordionHolder(*accordion_groups, css_id=None, css_class=None, template=None, **kwargs)

  Bases: `Accordion`

  Accordion items holder object to wrap Accordion item objects in a container:

      AccordionHolder(
          AccordionItem("group name", "form_field_1", "form_field_2"),
          AccordionItem("another group name", "form_field"),
      )

  `AccordionHolder` direct children should allways be a `AccordionItem` layout item.

  A random id is builded for the accordion holder if you don’t define it using `css_id` argument.

  The first `AccordionItem` containing a field error will be marked as active if any, else this will be just the first `AccordionItem`.

  render(form, context, template_pack=<SimpleLazyObject: <function get_template_pack>>, **kwargs)

    Re-implement almost the same code from crispy_forms but using `form` instance to catch field errors.

class crispy_forms_foundation.layout.containers.AccordionItem(name, *fields, css_id=None, css_class=None, template=None, active=None, **kwargs)

  Bases: `AccordionGroup`

  Accordion item object. It wraps given fields inside an accordion tab. It takes accordion tab name as first argument.

  The item name is also slugified to build an id for the tab if you don’t define it using `css_id` argument.

  Example:

      AccordionItem("group name", "form_field_1", "form_field_2")