Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.8', '3.9', '3.10', '3.11', '3.12']
python: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
Expand All @@ -37,7 +37,7 @@ jobs:
python-version: ${{ matrix.python }}
- uses: snok/install-poetry@v1
with:
version: '1.8.3'
version: '1.8.5'
virtualenvs-create: true
virtualenvs-in-project: true
- id: poetry-cache
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20
24
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repos:
hooks:
- id: isort
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 7.3.0
hooks:
- id: flake8
- repo: https://github.com/python/black
Expand Down
57 changes: 57 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Repository Guidelines

## Project Structure & Module Organization

`tbxforms/` contains the Django package. Core Python modules live at the
package root, reusable layout objects are in `tbxforms/layout/`, template tags
are in `tbxforms/templatetags/`, Django templates are in
`tbxforms/templates/tbxforms/`, and source styles/scripts are in
`tbxforms/static/`. Tests mirror those areas under `tests/`, with snapshot HTML
fixtures in `tests/**/__snapshots__/`. Build outputs are written to `dist/` and
packaged static assets.

## Build, Test, and Development Commands

Use Poetry for Python environment management in this repository.

- `poetry install` installs Python dependencies.
- `npm install` installs frontend build and lint dependencies.
- `poetry run pytest` runs the test suite against the active environment.
- `poetry run tox` runs the supported Python/Django matrix from `tox.ini`.
- `poetry run pytest --snapshot-update` updates Syrupy snapshots after checking
the rendered HTML change is intentional.
- `pre-commit run --all-files` runs Python, template, JS, and formatting checks.
- `npm run lint` runs ESLint and Prettier checks.
- `npm run build` builds the Vite bundle and copies Sass into `dist/`.

## Coding Style & Naming Conventions

Python uses Black and isort with a 79-character line length. Flake8 enforces the
same line length and a maximum complexity of 18. Use 4-space indentation for
Python, Sass, CSS, and Markdown; use 2 spaces for JavaScript, JSON, and YAML.
Django templates use `djlint` with the Django profile. Keep public layout and
field classes named descriptively, matching existing patterns such as
`Fieldset`, `Checkboxes`, and `DateInputField`.

## Testing Guidelines

Tests use pytest, Django test settings from `tests/settings.py`, and Syrupy for
HTML snapshots. Name test files `test_*.py` and place new coverage beside the
feature area, for example `tests/layout/test_select.py` for layout rendering.
For template output changes, review snapshot diffs before updating fixtures.
Run targeted pytest during development, then `poetry run tox` for compatibility
changes.

## Commit & Pull Request Guidelines

Recent history uses short, imperative commit subjects, often with GitHub PR
numbers, for example `Fix radios not including 'required' attribute when set as required (#98)`. Keep commits focused. Pull requests should describe the change,
link the related issue when available, mention snapshot or visual changes, and
list the checks run. Include screenshots or rendered HTML examples when form
markup or styling changes.

## Agent-Specific Instructions

Start new work on a branch and ask for the branch name first. Prefer Poetry when
managing Python dependencies here, despite the general preference for UV in
non-Poetry projects.
116 changes: 58 additions & 58 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,67 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## Types of changes

- `Added` for new features.
- `Changed` for changes in existing functionality.
- `Deprecated` for soon-to-be removed features.
- `Developer` for changes to the developer experience.
- `Fixed` for bug fixes.
- `Pinned packages updated` to list pinned packages that have been updated. Do not write changelog entries for third-party dependencies.
- `Removed` for now removed features.
- `Added` for new features.
- `Changed` for changes in existing functionality.
- `Deprecated` for soon-to-be removed features.
- `Developer` for changes to the developer experience.
- `Fixed` for bug fixes.
- `Pinned packages updated` to list pinned packages that have been updated. Do not write changelog entries for third-party dependencies.
- `Removed` for now removed features.

## Unreleased

## [4.3.1](https://github.com/torchbox/tbxforms/releases/tag/v4.3.1)

### Fixed

- Radio fields not being marked as `required` when set to be [#98]
- Radio fields not being marked as `required` when set to be [#98]

## [4.3.0](https://github.com/torchbox/tbxforms/releases/tag/v4.3.0)

### Added

- Allow per-form override of `settings.TBXFORMS_HIGHLIGHT_REQUIRED_FIELDS` [#97]
- Allow per-form override of `settings.TBXFORMS_HIGHLIGHT_REQUIRED_FIELDS` [#97]

## [4.2.0](https://github.com/torchbox/tbxforms/releases/tag/v4.2.0)

### Fixed

- Conditional fields not working when applied to field objects (e.g. `Field.text`, `Field.checkboxes`) instead of container objects (e.g. `Div`, `Fieldset`) [#95]
- Conditional fields not working when applied to field objects (e.g. `Field.text`, `Field.checkboxes`) instead of container objects (e.g. `Div`, `Fieldset`) [#95]

## [4.1.0](https://github.com/torchbox/tbxforms/releases/tag/v4.1.0)

### Added

- Error summary can be hidden [#93]
- Error summary can be hidden [#93]

### Changed

- Small tweak to fieldset styles [#93]
- Small tweak to fieldset styles [#93]

## [4.0.0](https://github.com/torchbox/tbxforms/releases/tag/v4.0.0)

### Changed

- Renamed `tbx` template directory and crispy forms template pack to `tbxforms` [#92]
- Renamed `tbx` template directory and crispy forms template pack to `tbxforms` [#92]

### Fixed

- Conditional fields not working properly when there are multiple elements inspecting the same driving field [#91]
- Conditional fields not working properly when there are multiple elements inspecting the same driving field [#91]

### Removed

- IE11 support [#91]
- IE11 support [#91]

## [3.0.0](https://github.com/torchbox/tbxforms/releases/tag/v3.0.0)

### Developer

- Guidance on how to update `govuk-frontend` [#80]
- Guidance on how to update `govuk-frontend` [#80]

### Pinned packages updated

- `govuk-frontend` from 3.13.0 (possibly) to 5.4.1 [#80]
- `govuk-frontend` from 3.13.0 (possibly) to 5.4.1 [#80]

### Removed

Expand All @@ -80,88 +80,88 @@ added which have now been removed and those which GDS have removed over time.

However, variables which have now been removed from our \_variables.scss are:

- `$tbxforms-border-colour-conditional` (no longer configurable; now using GDS' `$tbxforms-border-colour`) [#80]
- `$tbxforms-border-width-conditional` (no longer configurable; now using GDS' `$tbxforms-border-width`) [#80]
- `$tbxforms-weight--bold` (use `$tbxforms-font-weight-bold` instead) [#80]
- `$tbxforms-weight--normal` (use `$tbxforms-font-weight-regular` instead) [#80]
- `$tbxforms-grid` (no longer configurable; now using GDS' default spacing) [#80]
- `$tbxforms-spacer` (no longer configurable; now using GDS' default spacing) [#80]
- `$tbxforms-in-field-spacer` (no longer configurable; now using GDS' default spacing) [#80]
- `$tbxforms-form-group-spacer` (no longer configurable; now using GDS' default spacing) [#80]
- `$tbxforms-base-font-size` (use `$tbxforms-typography-scale` instead) [#80]
- `$tbxforms-base-line-height` (use `$tbxforms-typography-scale` instead) [#80]
- `$tbxforms-font-sizes` (use `$tbxforms-typography-scale` instead) [#80]
- `$tbxforms-border-colour-conditional` (no longer configurable; now using GDS' `$tbxforms-border-colour`) [#80]
- `$tbxforms-border-width-conditional` (no longer configurable; now using GDS' `$tbxforms-border-width`) [#80]
- `$tbxforms-weight--bold` (use `$tbxforms-font-weight-bold` instead) [#80]
- `$tbxforms-weight--normal` (use `$tbxforms-font-weight-regular` instead) [#80]
- `$tbxforms-grid` (no longer configurable; now using GDS' default spacing) [#80]
- `$tbxforms-spacer` (no longer configurable; now using GDS' default spacing) [#80]
- `$tbxforms-in-field-spacer` (no longer configurable; now using GDS' default spacing) [#80]
- `$tbxforms-form-group-spacer` (no longer configurable; now using GDS' default spacing) [#80]
- `$tbxforms-base-font-size` (use `$tbxforms-typography-scale` instead) [#80]
- `$tbxforms-base-line-height` (use `$tbxforms-typography-scale` instead) [#80]
- `$tbxforms-font-sizes` (use `$tbxforms-typography-scale` instead) [#80]

## [2.1.0](https://github.com/torchbox/tbxforms/releases/tag/v2.1.0)

### Changed

- Allow required fields to be highlighted instead of optional ones [#78]
- Allow markup in error messages [#79]
- Allow required fields to be highlighted instead of optional ones [#78]
- Allow markup in error messages [#79]

### Fixed

- Choice hints not showing on Django 5.x [#69]
- Choice hints not showing on Django 5.x [#69]

## [2.0.1](https://github.com/torchbox/tbxforms/releases/tag/v2.0.1)

### Pinned packages updated

- `vite` from 2.9.17 to 2.9.18 [#77]
- `black` from 22.3.0 to 24.3.0 [#77]
- `poetry` from 1.7.1 to 1.8.3 [#77]
- `vite` from 2.9.17 to 2.9.18 [#77]
- `black` from 22.3.0 to 24.3.0 [#77]
- `poetry` from 1.7.1 to 1.8.3 [#77]

## [2.0.0](https://github.com/torchbox/tbxforms/releases/tag/v2.0.0)

### Added

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

### Changed

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

### Removed

- 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) [#61] [#62]
- `sass` support for <1.33.0 [#60]
- 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) [#61] [#62]
- `sass` support for <1.33.0 [#60]

### Fixed

- Documentation referencing an incorrect CSS import path
- Documentation referencing an incorrect CSS import path

### Pinned packages updated

- `django` from 2.2.x to 3.2.x [#61]
- `django-crispy-forms` from 1.13.x to 2.1.x [#61]
- `flake8` from 4.0.1 to 5.0.4 [#61]
- `django` from 2.2.x to 3.2.x [#61]
- `django-crispy-forms` from 1.13.x to 2.1.x [#61]
- `flake8` from 4.0.1 to 5.0.4 [#61]

## [1.1.0](https://github.com/torchbox/tbxforms/releases/tag/v1.1.0)

### Added

- Support for dividers on checkbox fields
- 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
- 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

### Developer

- Template linting to CI using `djlint`
- Snapshot formatting check to CI using `djlint`
- Autoformatting of snapshots using `djlint`
- Testing across Django versions 2.2 - 4.0 and Python versions 3.8 - 3.11 using `tox`
- Use snapshot testing plugin (syrupy) for component rendering tests instead of HTML fixtures
- Template linting to CI using `djlint`
- Snapshot formatting check to CI using `djlint`
- Autoformatting of snapshots using `djlint`
- Testing across Django versions 2.2 - 4.0 and Python versions 3.8 - 3.11 using `tox`
- Use snapshot testing plugin (syrupy) for component rendering tests instead of HTML fixtures

### 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
- `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
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ variables can be customised.

## Requirements

- python `>=3.8.1,<4.0`
- Django `>=3.2`
- django-crispy-forms `>=2.1,<3.0`
- wagtail `>=2.15` if using `WagtailBaseForm`
- sass `>=1.33.0` if building the sass yourself
- python `>=3.9,<4.0`
- Django `>=4.2`
- django-crispy-forms `>=2.1,<3.0`
- wagtail `>=2.15` if using `WagtailBaseForm`
- sass `>=1.33.0` if building the sass yourself

<!-- prettier-ignore-start -->
> [!NOTE]
Expand Down Expand Up @@ -101,7 +101,7 @@ Import the styles into your project...
```scss
@use 'node_modules/tbxforms/tbxforms.scss' with (
$tbxforms-text-colour: #000,
$tbxforms-error-colour: #f00,
$tbxforms-error-colour: #f00
);
```

Expand Down Expand Up @@ -197,12 +197,12 @@ allows you to alter the rendering behaviour of forms.
Every form that inherits from `TbxFormsMixin` (i.e. every form within `tbxforms`)
will have a `FormHelper` with the following default attributes:

- `highlight_required_fields`: see [later section on highlighting required fields](#highlight-required-fields-instead-of-optional-ones)
- `html5_required = True`
- `label_size = Size.MEDIUM`
- `legend_size = Size.MEDIUM`
- `form_error_title = _("There is a problem with your submission")`
- Plus everything from [django-crispy-forms' default attributes](https://django-crispy-forms.readthedocs.io/en/latest/form_helper.html).
- `highlight_required_fields`: see [later section on highlighting required fields](#highlight-required-fields-instead-of-optional-ones)
- `html5_required = True`
- `label_size = Size.MEDIUM`
- `legend_size = Size.MEDIUM`
- `form_error_title = _("There is a problem with your submission")`
- Plus everything from [django-crispy-forms' default attributes](https://django-crispy-forms.readthedocs.io/en/latest/form_helper.html).

These can be changed during instantiation or [on the go](https://django-crispy-forms.readthedocs.io/en/latest/dynamic_layouts.html) - examples below.

Expand Down Expand Up @@ -415,8 +415,8 @@ class ExampleForm(TbxFormsMixin, forms.Form):

You can also style these markers by targeting these CSS classes:

- `.tbxforms-field_marker--required`
- `.tbxforms-field_marker--optional`
- `.tbxforms-field_marker--required`
- `.tbxforms-field_marker--optional`

### Change the default label and legend classes

Expand Down Expand Up @@ -462,8 +462,8 @@ it in your template.

# Further reading

- Download the [PyPI package](http://pypi.python.org/pypi/tbxforms)
- Download the [NPM package](https://www.npmjs.com/package/tbxforms)
- Learn more about [Django Crispy Forms](https://django-crispy-forms.readthedocs.io/en/latest/)
- Learn more about [Crispy Forms GDS](https://github.com/wildfish/crispy-forms-gds)
- Learn more about [GOV.UK Design System](https://design-system.service.gov.uk/)
- Download the [PyPI package](http://pypi.python.org/pypi/tbxforms)
- Download the [NPM package](https://www.npmjs.com/package/tbxforms)
- Learn more about [Django Crispy Forms](https://django-crispy-forms.readthedocs.io/en/latest/)
- Learn more about [Crispy Forms GDS](https://github.com/wildfish/crispy-forms-gds)
- Learn more about [GOV.UK Design System](https://design-system.service.gov.uk/)
Loading
Loading