Improve brand colour inputs - #3082
Conversation
Brand colours are normalised before validation, so uppercase hex characters and a missing leading # no longer cause validation errors. Stored values stay in the canonical lowercase #-prefixed form the runner API and show page expect.
The prefix is decorative, so the form displays the stored colour without its leading # and relies on the model normalising submitted values. Hint and error text drop the # from the example to match what users should now type.
|
🎉 A review copy of this PR has been deployed! You can reach it at: https://pr-3082.admin.review.forms.service.gov.uk/ It may take 5 minutes or so for the application to be fully deployed and working. If it still isn't ready For the sign in details and more information, see the review apps wiki page. |
There was a problem hiding this comment.
🟢 Approval recommended
The changes are cohesive, covered by updated specs, and the normalisation approach cleanly preserves the model’s existing validation contract while improving accepted input formats.
Pull request overview
This PR improves the UX and data consistency of Brand colour fields by allowing users to enter hex values in more common formats (with/without #, upper/lowercase) while normalising persisted values to the canonical #-prefixed lowercase form expected downstream.
Changes:
- Normalises
header_background_colourandborder_colourbefore validation to#+ lowercase, stripped 6-digit hex. - Updates the brand new/edit forms to use a decorative
#prefix and to display stored values without the leading#. - Adjusts i18n hints/error messages and expands specs to cover the new accepted input variants and normalisation behavior.
File summaries
| File | Description |
|---|---|
| spec/requests/brands_controller_spec.rb | Adds request coverage for creating a brand with uppercase/unprefixed colour input and verifying normalisation. |
| spec/models/brand_spec.rb | Updates model validation expectations to accept multiple hex input formats and assert canonical normalised storage. |
| config/locales/en.yml | Updates hint/error examples to match the new “no leading # in input” UI guidance. |
| app/views/brands/new.html.erb | Adds # prefix UI and strips # from displayed values in the colour inputs. |
| app/views/brands/edit.html.erb | Adds # prefix UI and strips # from displayed values in the colour inputs. |
| app/models/brand.rb | Adds a before_validation normalisation step for colour attributes. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Makes the brand colour fields easier to use:
#. Values are normalised before validation, so stored values keep the canonical lowercase#-prefixed form the runner API expects.#as a text input prefix. The prefix is decorative and not submitted, which is why the form displays stored values without the leading#and the hint/error examples no longer include it. This suits how people usually copy hex codes: double-clicking one selects just the six characters, not the #, so pasted values typically arrive unprefixed.