Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback text for summary list values #411

Open
peteryates opened this issue Mar 31, 2023 · 0 comments
Open

Add fallback text for summary list values #411

peteryates opened this issue Mar 31, 2023 · 0 comments

Comments

@peteryates
Copy link
Member

peteryates commented Mar 31, 2023

Sometimes across projects we end up with 'or' statements within views so if a attribute is missing we display some relevant text instead, like this:

summary_list_row.with_value(text: object.stuff || "Not set")

It's a bit untidy and can get repetitive.

Perhaps if we allowed a fallback_text option that could have a default, we could remove some of this duplication and noise. When used on its own it might look like this:

summary_list_row.with_value(text: object.stuff, fallback_text: "Not set")

But with a default it's much cleaner.

# in config/components.rb
Govuk::Components.configure do |conf|
  default_summary_list_fallback_text: "Not set"
end

# in your view
summary_list_row.with_value(text: object.stuff)

Here, like we've done elsewhere, we could disable it on an ad hoc basis with fallback_text: false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant