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

2753 error panel needs extending to accept two errors for one input #2817

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 19 additions & 8 deletions src/components/error/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@

rmccar marked this conversation as resolved.
Show resolved Hide resolved
{% macro onsError(params) %}
{% set content %}
<p
class="ons-panel__error"
{% if params.attributes %}{% for attribute, value in (params.attributes.items() if params.attributes is mapping and params.attributes.items else params.attributes) %}{{ attribute }}{% if value %}="{{ value }}"{% endif %} {% endfor %}{% endif %}
>
<strong>{{ params.text }}</strong>
</p>
{% if params.text is not string %}
<ul class="ons-list ons-list--bare">
{% for item in params.text %}
<li class="ons-panel__error ons-list__item"
{% if params.attributes %}{% for attribute, value in (params.attributes.items() if params.attributes is mapping and params.attributes.items else params.attributes) %}{{ attribute }}{% if value %}="{{ value }}"{% endif %} {% endfor %}{% endif %}
>
<strong>{{ item }}</strong>
</li>
{% endfor %}
</ul>
{% else %}
<p class="ons-panel__error"
{% if params.attributes %}{% for attribute, value in (params.attributes.items() if params.attributes is mapping and params.attributes.items else params.attributes) %}{{ attribute }}{% if value %}="{{ value }}"{% endif %} {% endfor %}{% endif %}
>
<strong>{{ params.text }}</strong>
</p>
{% endif %}
{{ caller() }}
{% endset %}

{% call onsPanel({
"type": "error",
"id": params.id
}) %}
{{ content | safe }}
{{ content | safe }}
{% endcall %}
{% endmacro %}
{% endmacro %}
22 changes: 17 additions & 5 deletions src/components/error/_macro.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,23 @@ describe('macro: error', () => {
),
);

expect(
$('.ons-panel__error')
.text()
.trim(),
).toBe('Example error text.');
expect($('.ons-panel__error').text().trim()).toBe('Example error text.');
});

it('has the provided error messages when the `text` param is set to an array type', () => {
const $ = cheerio.load(
renderComponent(
'error',
{
text: ['Example error text.', 'Example error text 2.'],
id: 'example-error',
},
FAKE_NESTED_CONTENT,
),
);

expect($('.ons-panel__error').text().trim()).toContain('Example error text.');
expect($('.ons-panel__error').text().trim()).toContain('Example error text 2.');
});

it('applies the provided `attributes` to the error content paragraph', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

{% from "components/date-input/_macro.njk" import onsDateInput %}
{% from "components/panel/_macro.njk" import onsPanel %}
{% from "components/list/_macro.njk" import onsList %}

{% call
onsPanel({
title: "There is a problem with this page",
type: "error"
})
%}

{{
onsList({
"element": "ol",
"itemsList": [
{
"text": "Enter a number between 1 to 12",
"url": "#date-input-error",
"variants": "inPageLink"
},
{
"text": "Enter a date that is after 1 January 2019",
"url": "#date-input-error",
"variants": "inPageLink"
}
]
})
}}
{% endcall %}

{{
onsDateInput({
"id": "period-to-date",
"legendOrLabel": "Period to:",
"description": "For example, 31 3 2020",
"day": {
"label": {
"text": "Day"
},
"name": "day",
"value": "31"
},
"month": {
"label": {
"text": "Month"
},
"name": "month",
"value": "13",
"error": true
},
"year": {
"label": {
"text": "Year"
},
"name": "year",
"value": "2018",
"error": true
},
"error": {
"id": "date-input-error",
"text": [
"Enter a number between 1 to 12",
"Enter a date that is after 1 January 2019"
]
}
})
}}
Loading