Skip to content

v1.1.0

Compare
Choose a tag to compare
@kbayliss kbayliss released this 16 Aug 13:04
· 18 commits to main since this release

What's changed

Added

  • Support for dividers on checkbox fields

Changed

  • form.helper (FormHelper) changed from a static @property to the form's __init__ method to allow changes at runtime
  • Update documentation and examples to use Field subclass methods (e.g. Field.select) to avoid passing context dictionary to Field (https://crispy-forms-gds.readthedocs.io/en/latest/reference/layout/field.html)
  • BaseForm renamed to TbxFormsMixin to more accurately convey what it is
  • Styles no longer depend on the form having the .tbxforms class (note: the JavaScript still does!)

Developer

  • Added template linting to CI using djlint
  • Added syrupy snapshot testing and removed the static/manual HTML fixtures
  • We're now testing across Django versions 2.2 - 4.0 and Python versions 3.8 - 3.11 using tox

Fixed

  • Field.select label size and tag can be changed
  • DateInputField no longer raises a ValueError when given invalid input (a ValidationError is raised instead)
  • DateInputField with required=False no longer raises a ValueError when no values are passed
  • DateInputField no longer errors with OverflowError when large values are passed

Upgrade considerations

BaseForm is now named TbxFormsMixin

You must update references from tbxforms.forms.BaseForm to tbxforms.forms.TbxFormsMixin. This change better conveys what TbxFormsMixin is - a mixin that does not inherit from any of Django's base form classes.

FormHelper is now added via the TbxFormsMixin.__init__ method instead of via a helper property

You should replace any form.helper properties with form helpers that are instantiated via the form __init__ method - e.g.:

From:

class YourSexyForm(...):
    ...

    @property
    def helper(self):
        fh = super().helper

        # Use HTML5 validation
        fh.html5_required = True

        # Add a submit button
        fh.layout.extend([
            Button.primary(
                name="submit",
                type="submit",
                value="Submit",
            )
        ])
        return fh

To:

class YourSexyForm(...):
    ...

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        
        # Use HTML5 validation
        self.helper.html5_required = True

        # Add a submit button
        self.helper.layout.extend([
            Button.primary(
                name="submit",
                type="submit",
                value="Submit",
            )
        ])

You must not instantiate your own FormHelper() - you should inherit from the existing helper (self.helper).

While using a static helper property is still supported (as this is core Django Crispy Forms behaviour), tbxforms no longer provides a helper property to inherit from.

This change allows you to change the FormHelper on the go - see https://django-crispy-forms.readthedocs.io/en/latest/dynamic_layouts.html for more information on this.

In most cases, Field(...) layout slices should now subclass specific fields, e.g. Field.text(...)

You should update all Field(...) layout slices to use one of the more specific subclasses:

  • Field.checkbox(...)
  • Field.checkboxes(...)
  • Field.radios(...)
  • Field.select(...)
  • Field.text(...)
  • Field.textarea(...)

See https://github.com/torchbox/tbxforms/blob/main/tbxforms/layout/fields.py for more information.

While Field(...) is still supported, the behaviour is not guaranteed. Using one of the more specific subclasses will align your fields with tbxforms and allow you to leverage key functionality more easily.

tbxforms styles are no longer nested under the .tbxforms class

While all tbxforms forms must still have a tbxforms class in order for conditional fields to work, the associated styles are no longer nested underneath the .tbxforms class.