Allow custom sort order for error summaries #290
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ordering can be defined in one of two ways:
passing in an
order
argument, to#govuk_error_summary
, e.g.,order: %i(name email date_of_birth)
configuring an
default_error_summary_error_order_method
method, like this:Then the error order can be defined on a per-model basis like this:
The method approach has the benefit of being automatically applied on any bound form automatically. The argument-based approach takes precedence and allows for some extra flexibility, but requires a little extra attention and possibly repetition.
Ordered attributes will have their error messages displayed first, in the order defined.
Any errors on attributes that aren't covered by #error_order will appear after those that are, in the order they were defined in the object or model.
If no custom ordering is provided the current default behaviour will apply and the errors will be displayed in the same order they're defined in the model.