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 for more control over formatting of prefix and postfix #1806

Merged
merged 2 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions assets/scss/modules/editor/fields/_pre_postfix.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
color: #666;
display: block;
margin: 0.5rem 0;

p {
max-width: 40em;
}
}
7 changes: 7 additions & 0 deletions config/bolt/contenttypes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ showcases:
error: "The Title field is required, and must contain at least 2 characters"
placeholder: "Placeholder for the title"
group: Text
postfix: |
This is an example of a longer "postfix". Simple text is capped at a reasonable width
to enhance legibility. Necessitatibus dolor corrupti assumenda placeat quia occati
aut. Facere porro placeat molestiae fuga. Laboriosam et asperiores atque impedit
dolorem dicta aut. Harum inventore ipsa voluptas consectetur quaerat eius ad.
<div class="alert alert-secondary" role="alert"><strong>Tip:</strong> You can even
use HTML in a prefix! Note that this one does take the full available width.</div>
slug:
type: slug
uses: [ title ]
Expand Down
8 changes: 4 additions & 4 deletions templates/_partials/fields/_base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@

{# Set the prefix and postfix attributes #}
{% set prefix = prefix|default(field.definition.prefix|default) %}
{% if prefix and not ('<p' in prefix or '<span' in prefix or '<div' in prefix) %}
{% set prefix = '<span id="' ~ id ~ '_prefix" class="form--helper">' ~ prefix ~ '</span>' %}
{% if prefix and not (prefix starts with '<p' or prefix starts with '<span' or prefix starts with '<div') %}
{% set prefix = '<div id="' ~ id ~ '_prefix" class="form--helper">' ~ prefix|markdown ~ '</div>' %}
{% endif %}

{% set postfix = postfix|default(field.definition.postfix|default) %}
{% if postfix and not ('<p' in postfix or '<span' in postfix or '<div' in postfix) %}
{% set postfix = '<span id="' ~ id ~ '_postfix" class="form--helper">' ~ postfix ~ '</span>' %}
{% if postfix and not (postfix starts with '<p' or postfix starts with '<span' or postfix starts with '<div') %}
{% set postfix = '<div id="' ~ id ~ '_postfix" class="form--helper">' ~ postfix|markdown ~ '</div>' %}
{% endif %}

{%- endapply -%}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/kitchensink.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ Feature: Visiting the Kitchensink

And I should see "Title:" in the "label[for='field-title']" element
And I should see an "input#field-title" element
And I should see "shown on the homepage" in the "span#field-title_postfix" element
And I should see "shown on the homepage" in the "div#field-title_postfix" element