Skip to content

Commit

Permalink
Add note about StreamField validation happening on the form
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrlpld authored and lb- committed Mar 13, 2024
1 parent 068c3f2 commit 77d783b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Changelog
* Docs: Update template components documentation to better explain the usage of the Laces library (Tibor Leupold)
* Docs: Update Sphinx theme to `6.3.0` with a fix for the missing favicon (Sage Abdullah)
* Docs: Document risk of XSS attacks on document upload (Matt Westcott, with thanks to Georgios Roumeliotis of TwelveSec for the original report)
* Docs: Add clarity to how custom StreamField validation works (Tibor Leupold)
* Maintenance: Move RichText HTML whitelist parser to use the faster, built in `html.parser` (Jake Howard)
* Maintenance: Remove duplicate 'path' in default_exclude_fields_in_copy (Ramchandra Shahi Thakuri)
* Maintenance: Update unit tests to always use the faster, built in `html.parser` & remove `html5lib` dependency (Jake Howard)
Expand Down
8 changes: 8 additions & 0 deletions docs/advanced_topics/streamfield_validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ class LinkBlock(StructBlock):
return result
```

```{note}
The validation of the blocks in the `StreamField` happens through the form field (`wagtail.blocks.base.BlockField`), not the model field (`wagtail.fields.StreamField`).
This means that calling validation methods on your page instance (such as `my_page.full_clean()`) won't catch invalid blocks in the `StreamField` data.
This should only be relevant when the data in the `StreamField` is added programmatically, through other paths than the form field.
```

## Controlling where error messages are rendered

In the above example, an exception of type `ValidationError` is raised, which causes the error to be attached and rendered against the StructBlock as a whole. For more control over where the error appears, the exception class `wagtail.blocks.StructBlockValidationError` can be raised instead. The constructor for this class accepts the following arguments:
Expand Down
1 change: 1 addition & 0 deletions docs/releases/6.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ depth: 1
* Update [template components](creating_template_components) documentation to better explain the usage of the Laces library (Tibor Leupold)
* Update Sphinx theme to `6.3.0` with a fix for the missing favicon (Sage Abdullah)
* Document risk of XSS attacks on document upload (Matt Westcott, with thanks to Georgios Roumeliotis of TwelveSec for the original report)
* Add clarity to how custom [StreamField validation](streamfield_validation) works (Tibor Leupold)


### Maintenance
Expand Down

0 comments on commit 77d783b

Please sign in to comment.