Skip to content

Releases: torchbox/tbxforms

v2.0.0

05 Feb 14:08
Compare
Choose a tag to compare

What's changed

Added

  • Python support for 3.12 [#61]
  • Django support for 4.1 and 4.2 [#61]

Changed

  • django-crispy-forms updated to 2.1.x [#61]

Deprecated

  • Django support for 2.2, 3.0, and 3.1 [#61]
  • TBXFORMS_ALLOW_HTML_LABEL, TBXFORMS_ALLOW_HTML_HELP_TEXT, and TBXFORMS_ALLOW_HTML_BUTTON settings (developers must now mark strings as safe to render markup within templates) [#61] [#62]
  • sass support for <1.33.0 [#60]

Fixed

  • Documentation referencing an incorrect CSS import path

Security

  • |safe is no longer applied within templates [#61]

See full changelog.

Upgrade considerations

Strings are now escaped by default

To show unescaped markup, you must mark any strings as safe (e.g. with mark_safe()) as values are now escaped by default. Previously, they were conditionally escaped based on the values of TBXFORMS_ALLOW_HTML_LABEL, TBXFORMS_ALLOW_HTML_HELP_TEXT, and TBXFORMS_ALLOW_HTML_BUTTON settings.

This applies to label, help_text, hint (for select and checkbox fields), and value for button fields.

You should remove the following settings:

  1. TBXFORMS_ALLOW_HTML_LABEL
  2. TBXFORMS_ALLOW_HTML_HELP_TEXT
  3. TBXFORMS_ALLOW_HTML_BUTTON

New contributors

v1.1.0

16 Aug 13:04
Compare
Choose a tag to compare

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.