Releases: torchbox/tbxforms
v2.0.0
What's changed
Added
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
, andTBXFORMS_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:
TBXFORMS_ALLOW_HTML_LABEL
TBXFORMS_ALLOW_HTML_HELP_TEXT
TBXFORMS_ALLOW_HTML_BUTTON
New contributors
- @olivierphi made their first contribution in #61
- @RealOrangeOne made their first contribution in #60
v1.1.0
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 passingcontext
dictionary toField
(https://crispy-forms-gds.readthedocs.io/en/latest/reference/layout/field.html) BaseForm
renamed toTbxFormsMixin
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 changedDateInputField
no longer raises aValueError
when given invalid input (aValidationError
is raised instead)DateInputField
withrequired=False
no longer raises aValueError
when no values are passedDateInputField
no longer errors withOverflowError
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.