Skip to content

Commit

Permalink
* Fixed 'TabHolder' and 'AccordionHolder' to have the right *active* …
Browse files Browse the repository at this point in the history
…behavior on their items: activate the first item with a field error if any, else just activate the first item;

* Bump to 0.5.4;
  • Loading branch information
sveetch committed Feb 26, 2016
1 parent ed275b9 commit 4ce2381
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 25 deletions.
2 changes: 1 addition & 1 deletion crispy_forms_foundation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"""
Django application to add 'django-crispy-forms' layout objects for Foundation
"""
__version__ = '0.5.3'
__version__ = '0.5.4'
4 changes: 2 additions & 2 deletions crispy_forms_foundation/layout/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
See :
* `Foundation buttons <http://foundation.zurb.com/docs/components/buttons.html>`_ for button components;
* `Foundation button groups <http://foundation.zurb.com/docs/components/button_groups.html>`_ for button groups components;
* `Foundation buttons <http://foundation.zurb.com/sites/docs/v/5.5.3/components/buttons.html>`_ for button components;
* `Foundation button groups <http://foundation.zurb.com/sites/docs/v/5.5.3/components/button_groups.html>`_ for button groups components;
"""
from django.conf import settings
from django.template import Context
Expand Down
30 changes: 19 additions & 11 deletions crispy_forms_foundation/layout/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
See :
* `Foundation forms <http://foundation.zurb.com/docs/components/forms.html>`_ for fieldset component;
* `Foundation Accordion <http://foundation.zurb.com/docs/components/accordion.html>`_ for accordion components;
* `Foundation Tabs <http://foundation.zurb.com/docs/components/tabs.html>`_ for tabs components;
* `Foundation forms <http://foundation.zurb.com/sites/docs/v/5.5.3/components/forms.html>`_ for fieldset component;
* `Foundation Accordion <http://foundation.zurb.com/sites/docs/v/5.5.3/components/accordion.html>`_ for accordion components;
* `Foundation Tabs <http://foundation.zurb.com/sites/docs/v/5.5.3/components/tabs.html>`_ for tabs components;
"""
from random import randint

Expand Down Expand Up @@ -60,18 +60,21 @@ class TabHolder(crispy_forms_bootstrap.TabHolder):
TabItem('My tab 2', 'form_field_3')
)
``TabHolder`` directl children should allways be a ``TabItem`` layout item.
``TabHolder`` direct children should allways be a ``TabItem`` layout item.
The first ``TabItem`` containing a field error will be marked as
*active* if any, else this will be just the first ``TabItem``.
"""
template = "{0}/layout/tab-holder.html".format(TEMPLATE_PACK)
default_active_tab = None

def render(self, form, form_style, context, template_pack=TEMPLATE_PACK):
links, content = '', ''
for tab in self.fields:
tab.active = False

# The first tab with errors will be active
if self.first_container_with_errors(form.errors.keys()) is not None:
self.first_container_with_errors(form.errors.keys()).active = True
# Activate item
self.open_target_group_for_form(form)

for tab in self.fields:
content += render_field(
Expand Down Expand Up @@ -132,6 +135,11 @@ class AccordionHolder(crispy_forms_bootstrap.Accordion):
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.
The first ``AccordionItem`` containing a field error will be marked as
*active* if any, else this will be just the first ``AccordionItem``.
"""
template = "{0}/layout/accordion-holder.html".format(TEMPLATE_PACK)

Expand All @@ -142,10 +150,10 @@ def render(self, form, form_style, context, template_pack=TEMPLATE_PACK):
# know why). This needs to be a unique id
if not self.css_id:
self.css_id = "-".join(["accordion", text_type(randint(1000, 9999))])

# first group with errors or first group will be visible, others will be collapsed
if self.first_container_with_errors(form.errors.keys()) is not None:
self.first_container_with_errors(form.errors.keys()).active = True
# Active first 'AccordionItem' containing a field error if any, else
# active first holder item
self.open_target_group_for_form(form)

for group in self.fields:
group.data_parent = self.css_id
Expand Down
8 changes: 4 additions & 4 deletions crispy_forms_foundation/layout/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
See :
* `Foundation forms <http://foundation.zurb.com/docs/components/forms.html>`_ for input field components;
* `Foundation Switches <http://foundation.zurb.com/docs/components/switch.html>`_ for switches components;
* `Foundation forms <http://foundation.zurb.com/sites/docs/v/5.5.3/components/forms.html>`_ for input field components;
* `Foundation Switches <http://foundation.zurb.com/sites/docs/v/5.5.3/components/switch.html>`_ for switches components;
"""
from django.conf import settings

Expand All @@ -19,7 +19,7 @@ class MultiWidgetField(crispy_forms_layout.MultiWidgetField): pass

class Field(crispy_forms_layout.Field):
"""
Layout object, It contains one field name, and you can add attributes to it easily.
Layout object, contain one field name and you can add attributes to it easily.
For setting class attributes, you need to use `css_class`, as `class` is a Python keyword.
Example:
Expand All @@ -33,7 +33,7 @@ class Field(crispy_forms_layout.Field):

class MultiField(crispy_forms_layout.MultiField):
"""
MultiField container. Renders to a MultiField
MultiField container. Render to a MultiField
"""
template = "{0}/layout/multifield.html".format(TEMPLATE_PACK)
field_template = "{0}/multifield.html".format(TEMPLATE_PACK)
Expand Down
12 changes: 6 additions & 6 deletions crispy_forms_foundation/layout/grid.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""
.. _Foundation Grid: http://foundation.zurb.com/sites/docs/v/5.5.3/components/grid.html
Foundation grid layout objects
See `Foundation Grid <http://foundation.zurb.com/docs/components/grid.html>`_ for grid components.
See `Foundation Grid`_ for grid components.
"""
from django.conf import settings
from django.template import Context
Expand All @@ -17,7 +19,7 @@

class Row(Div):
"""
It wraps fields in a div whose default class is ``row``. Example:
Wrap fields in a div whose default class is ``row``. Example:
.. sourcecode:: python
Expand All @@ -33,7 +35,7 @@ class Row(Div):

class RowFluid(Row):
"""
It wraps fields in a div whose default class is "row row-fluid". Example:
Wrap fields in a div whose default class is "row row-fluid". Example:
.. sourcecode:: python
Expand Down Expand Up @@ -88,9 +90,7 @@ class RowFluid(Row):

class Column(Div):
"""
.. _Foundation Grid: http://foundation.zurb.com/docs/components/grid.html
It wraps fields in a div. If not defined, CSS class will default to
Wrap fields in a div. If not defined, CSS class will default to
``large-12 columns``. ``columns`` class is always appended, so you don't
need to specify it.
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
Changelog
=========

Version 0.5.4
*************

* Fixed ``TabHolder`` and ``AccordionHolder`` to have the right *active* behavior on their items: activate the first item with a field error if any, else just activate the first item;

Version 0.5.3
*************

Expand Down
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ Contributors
.. _`@carsolcas`: https://github.com/carsolcas
.. _`@sbaechler`: https://github.com/sbaechler
.. _`@bionikspoon`: https://github.com/bionikspoon
.. _`@flesser`: https://github.com/flesser

* Philip Garnero (`@PhilipGarnero`_);
* Juerg Rast (`@jrast`_);
* JR (`@jayarnielsen`_);
* Carsolcas (`@carsolcas`_);
* Simon Bächler (`@sbaechler`_);
* Manu Phatak (`@bionikspoon`_);
* Florian Eßer (`@flesser`_);
1 change: 0 additions & 1 deletion docs/layout.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.. _django-crispy-forms: https://github.com/maraujop/django-crispy-forms
.. _Foundation: http://github.com/zurb/foundation
.. _Foundation Grid: http://foundation.zurb.com/docs/components/grid.html
.. _crispy-forms-foundation-demo: https://github.com/sveetch/crispy-forms-foundation-demo
.. _Abide: http://foundation.zurb.com/docs/components/abide.html

Expand Down

0 comments on commit 4ce2381

Please sign in to comment.