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

Allow suppression of elements by passing in nil #213

Merged
merged 2 commits into from
Nov 3, 2020

Conversation

peteryates
Copy link
Member

This addresses a problem where elements are always rendered if there's a matching localisation key, even if nil is supplied to the helper.

Introducing a Elements::Null class simplifies the logic - an alternative solution was to introduce an :enabled flag but as we already have :active it was noisy and confusing.

When the relevant argument (:caption, :hint, :label or :legend) is nil a Elements::Null is built instead of the usual 'active' element. It will never render any HTML and allows the suppression of elements.

The default argument for captions, hints, labels and legends is always an empty hash, so simply not providing any arguments will allow the localisation mechanism to kick in and populate the element.

Fixes #212

@peteryates peteryates added the bug Something isn't working label Oct 31, 2020
@peteryates peteryates force-pushed the allow-suppression-of-elements-via-nil branch 2 times, most recently from b70d875 to 890e6ef Compare October 31, 2020 11:40
This addresses a problem where elements are always rendered if there's a
matching localisation key, even if `nil` is supplied to the helper.

Introducing a Elements::Null class simplifies the logic - an alternative
solution was to introduce an :enabled flag but as we already have
:active it was noisy and confusing.

When the relevant argument (:caption, :hint, :label or :legend) is nil a
Elements::Null is built instead of the usual 'active' element. It will
never render any HTML and allows the suppression of elements.

The default argument for captions, hints, labels and legends is always
an empty hash, so simply not providing any arguments will allow the
localisation mechanism to kick in and populate the element.

Fixes #212
@peteryates peteryates force-pushed the allow-suppression-of-elements-via-nil branch from 890e6ef to c21ca33 Compare October 31, 2020 12:29
Copy link
Collaborator

@cpjmcquillan cpjmcquillan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks 💫

Hints can be added to fieldset items and should be suppressable in the
same manner as regular helpers. A new field (stationery) was added
to the spec objects for this to avoid clashes in existing tests.

Refs #213
@peteryates peteryates merged commit 2462438 into master Nov 3, 2020
@peteryates peteryates deleted the allow-suppression-of-elements-via-nil branch November 3, 2020 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Collection check boxes hint reverts to translation file even when hint is nil
2 participants