{% from "govuk_frontend_jinja/components/back-link/macro.html" import govukBackLink %} {% from "govuk_frontend_jinja/components/task-list/macro.html" import govukTaskList %} {% from "govuk_frontend_jinja/components/summary-list/macro.html" import govukSummaryList %} {% from "govuk_frontend_jinja/components/details/macro.html" import govukDetails %} {% from "govuk_frontend_jinja/components/inset-text/macro.html" import govukInsetText %} {% from "common/macros/status.html" import tasklistSectionStatusTag with context %} {% macro collection_before(runner, override_back_link=None) %} {{ govukBackLink({ "text": "Back", "href": override_back_link or runner.back_url }) }} {% endmacro %} {% macro collection_question_with_add_another_summary_page(runner) %} {% if runner.add_another_summary_context %} {{ collection_add_another_summary(runner) }} {% elif runner.is_removing %} {{ collection_add_another_confirm_remove(runner) }} {% elif runner.is_clearing %} {{ collection_question_confirm_remove(runner) }} {% else %} {{ collection_question(runner) }} {% endif %} {% endmacro %} {% macro collection_render_single_question(form, question, interpolator, questionAsPageHeading) %} {% if question.data_type == enum.question_type.TEXT_MULTI_LINE %} {{ form.render_question( question, params={ "label": {"classes": "govuk-label--l" if questionAsPageHeading else "govuk-!-font-weight-bold", "isPageHeading": questionAsPageHeading}, "maxwords": question.presentation_options.word_limit, "rows": question.presentation_options.rows, "attributes": {"data-module": "paste-html-bullets-as-markdown"}, } ) }} {% elif question.data_type == enum.question_type.TEXT_SINGLE_LINE or question.data_type == enum.question_type.EMAIL or question.data_type == enum.question_type.URL %} {{ form.render_question( question, params={ "label": {"classes": "govuk-label--l" if questionAsPageHeading else "govuk-!-font-weight-bold", "isPageHeading": questionAsPageHeading} } ) }} {% elif question.data_type == enum.question_type.NUMBER %} {{ form.render_question( question, params={ "label": {"classes": "govuk-label--l" if questionAsPageHeading else "govuk-!-font-weight-bold" ,"isPageHeading": questionAsPageHeading}, "inputmode": "numeric", "spellcheck": false, "classes": question.presentation_options.width or '', "prefix": {"text": question.presentation_options.prefix or ''}, "suffix": {"text": question.presentation_options.suffix or ''} } ) }} {% elif question.data_type == enum.question_type.YES_NO %} {{ form.render_question( question, params={ "fieldset": {"legend": {"text": interpolator(question.text), "classes": "govuk-fieldset__legend--l" if questionAsPageHeading else "govuk-!-font-weight-bold", "isPageHeading": questionAsPageHeading} }, "classes": "govuk-radios--inline" } ) }} {% elif question.data_type == enum.question_type.CHECKBOXES %} {{ form.render_question( question, params={ "fieldset": {"legend": {"text": interpolator(question.text), "classes": "govuk-fieldset__legend--l" if questionAsPageHeading else "govuk-!-font-weight-bold", "isPageHeading": questionAsPageHeading} }, } ) }} {% elif question.data_type == enum.question_type.DATE %} {{ form.render_question( question, params={ "fieldset": {"legend": {"text": interpolator(question.text), "classes": "govuk-fieldset__legend--l" if questionAsPageHeading else "govuk-!-font-weight-bold", "isPageHeading": questionAsPageHeading} }, "spellcheck": false } ) }} {% elif question.data_type == enum.question_type.RADIOS %} {% if form.get_question_field(question).widget.is_accessible_autocomplete %} {# `govuk-!-width-full` override here to line up with the default width of the accessible autocomplete component. We could potentially do something smarter, like copy the class from here to the enhanced autocomplete, but leaving that for a future increment. #} {{ form.render_question( question, params={ "label": {"classes": "govuk-fieldset__legend--l" if questionAsPageHeading else "govuk-!-font-weight-bold", "isPageHeading": questionAsPageHeading}, "classes": "govuk-!-width-full" } ) }} {% else %} {{ form.render_question( question, params={ "fieldset": {"legend": {"text": interpolator(question.text), "classes": "govuk-fieldset__legend--l" if questionAsPageHeading else "govuk-!-font-weight-bold", "isPageHeading": questionAsPageHeading} }, } ) }} {% endif %} {% elif question.data_type == enum.question_type.FILE_UPLOAD %} {% set existing_file_upload_answer = runner.submission.cached_get_answer_for_question(question.id, add_another_index=runner.add_another_index if runner.add_another_index is not none else none) %} {% if existing_file_upload_answer %} {% if questionAsPageHeading %}
You can remove this file if you need to upload a different one.
{% else %} {{ form.render_question( question, params={ "label": {"classes": "govuk-label--l" if questionAsPageHeading else "govuk-!-font-weight-bold", "isPageHeading": questionAsPageHeading}, "attributes": { "accept": (question.file_types_supported | sum(attribute='mime_types', start=[]) | join(',')) if question.file_types_supported else None }, "javascript": true, } ) }} {% set upload_guidance %}You can upload the following file types:
Your file must be smaller than {{ question.maximum_file_size.human_readable }}.
{% endset %} {{ govukDetails({ "summaryText": "What file types can I upload?", "html": upload_guidance, }) }} {% endif %} {% endif %} {% endmacro %} {% macro collection_question(runner) %} {% set is_group = runner.component.is_group %} {% set questions = runner.questions if is_group else [runner.component] %} {% set form = runner.question_form %} {% set questionAsPageHeading = not runner.component.guidance_heading and not is_group %} {% set contains_file_upload = questions | selectattr("data_type", "equalto", enum.question_type.FILE_UPLOAD) | list | length > 0 %} {% endmacro %} {% macro summary_list_for_answers(container, runner, add_another_index=none, summary_title=none) %} {# each container context will have its own summary list which we'll populate at the end of this macro #} {% set form = runner.form %} {% set submission = runner.submission %} {% set add_another_contexts = [] %} {% set summary_list_rows = [] %} {% set is_add_another_group = add_another_index is not none %} {% set context = submission.cached_evaluation_context if not is_add_another_group else submission.cached_evaluation_context.with_add_another_context(container, submission.submission.data_manager, add_another_index=add_another_index) %} {% set interpolation_context = submission.cached_interpolation_context if not is_add_another_group else submission.cached_interpolation_context.with_add_another_context(container, submission.submission.data_manager, add_another_index=add_another_index, mode="interpolation") %} {% for question in submission.cached_get_ordered_visible_questions(container, override_context=context if is_add_another_group else none) %} {% if question.add_another_container and not is_add_another_group %} {# for the add another context we'll just include one row with a link to the full answers below #} {% if question.add_another_container not in (add_another_contexts | map(attribute="container")) %} {% set count = submission.get_count_for_add_another(question.add_another_container) %} {% set summaries = [] %} {% set status = namespace(all_answered = true) %} {% for i in range(count) %} {% set (summary, is_answered) = submission.get_answer_summary_for_add_another(question.add_another_container, add_another_index=i) %} {% do summaries.append({ "summary_text_line": summary, "is_answered": is_answered }) %} {% if not is_answered %}{% set status.all_answered = false %}{% endif %} {% endfor %} {% do add_another_contexts.append({ "container": question.add_another_container, "count": count, "summaries": summaries, "all_answered": status.all_answered }) %} {% set key_text = runner.interpolate(question.add_another_container.text) %} {# the add another context has been fully answered and should be checked on this page #} {% if count and status.all_answered %} {% set value_html %}You have added {% trans count=count %}{{ count }} answer{% pluralize %}{{ count }} answers{% endtrans %}
Answers for “{{ question.add_another_container.name }}”
{% endset %} {% set actions = [] if not runner.can_edit_question(question) else [{ "href": runner.to_url(enum.form_runner_state.QUESTION, question=question, source=enum.form_runner_state.CHECK_YOUR_ANSWERS), "text": "Change", "visuallyHiddenText": question.add_another_container.name, "classes": "govuk-link--no-visited-state" }] %} {% else %} {# the add another context is partially answered and should be completed before checking here #} {% set value_html %} {% if runner.can_edit_question(question) %} {{ "Enter" if not count else "Finish entering " }} {{ question.add_another_container.name | lower }} {% else %} ({{ "Not answered" if not count else "Not completely answered" }}) {% endif %} {% endset %} {% endif %} {% do summary_list_rows.append({ "key": {"text": key_text }, "value": {"html": value_html }, "actions": {"items": actions } if actions else none, }) %} {% endif %} {% else %} {# standard K:V question:answer context #} {% set answer = submission.cached_get_answer_for_question(question.id, add_another_index=add_another_index if add_another_index is not none else none) %} {% if answer is not none %} {% set value_html %} {% include answer._render_answer_template %} {% endset %} {# todo: can we "anchor" or link to the specific question if we're going to be changing a question on a same page group #} {% set actions = [] if not runner.can_edit_question(question) else [{ "href": runner.to_url(enum.form_runner_state.QUESTION, question=question, source=enum.form_runner_state.CHECK_YOUR_ANSWERS, add_another_index=add_another_index if add_another_index is not none else none), "text": "Change", "visuallyHiddenText": question.name, "classes": "govuk-link--no-visited-state" }] %} {% do summary_list_rows.append({ "key": { "text": runner.interpolate(question.text, context=interpolation_context if is_add_another_group else None) }, "value": { "html": value_html }, "actions": { "items": actions }, }) %} {% else %} {% set value_html %} {% if runner.can_edit_question(question) %} Enter {{ question.name }} {% else %} (Not answered) {% endif %} {% endset %} {% do summary_list_rows.append({ "key": { "text": runner.interpolate(question.text) }, "value": { "html": value_html } }) %} {% endif %} {% endif %} {% endfor %} {# fixme: this margin applied somewhere else #} {{ govukSummaryList({ "classes": "govuk-!-margin-bottom-9" if add_another_index is none else "", "rows": summary_list_rows, "card": { "title": { "text": summary_title if summary_title else "Answer " ~ ((add_another_index + 1) if is_add_another_group else "") } } if is_add_another_group else none }) }} {% for context in add_another_contexts %} {% if context.count and context.all_answered %}{{ submission.changes_requested_reason }}
This collection has no forms.
{% else %} {% set rows=[] %} {% for form in forms %} {% set can_start = submission.can_start_form(form) %} {% set hint_html = None %} {% if not can_start %} {% set link_href = None %} {% set blocking_sections = submission.get_referenced_forms_with_unanswered_references(form) %} {% set hint_html %} Requires answers from {{ blocking_sections | map(attribute='title') | comma_join_items }} {% endset %} {% else %} {% set first_question = submission.get_first_question_for_form(form) %} {% set link_href = ( '' if not first_question else runner.to_url(enum.form_runner_state.QUESTION, question=first_question) if (submission.get_status_for_form(form) == enum.tasklist_section_status.NOT_STARTED and runner.can_edit_form(form)) else runner.to_url(enum.form_runner_state.CHECK_YOUR_ANSWERS, form=form, source=enum.form_runner_state.TASKLIST) ) %} {% endif %} {% do rows.append({ "title": { "text": form.title, }, "status": { "html": tasklistSectionStatusTag(submission.get_tasklist_status_for_form(form)), }, "hint": { "html": hint_html, } if hint_html else {}, "href": link_href, }) %} {% endfor %} {{ govukTaskList({ "idPrefix": submission.collection.slug, "items": rows }) }} {% endif %}You must complete all sections before you can submit.
{% endset %} {% if runner.can_edit %}You have not added any {{ add_another_container.name | lower }}.
{% endif %} {% endmacro %} {% macro collection_add_another_confirm_remove(runner) %} {% set add_another_container = runner.component.add_another_container %} {% set (summary, is_answered) = runner.submission.get_answer_summary_for_add_another(add_another_container, add_another_index=runner.add_another_index) %} {# todo: tweak how the summary works so that its only generated if the #} {# form designer has explicitly select which answers should be included #} {# otherwise everything should default to "answer" by default #} {% set heading = "Are you sure you want to remove " ~ (summary or ('answer ' ~ (runner.add_another_index + 1))) ~ "?" %} {{ runner.component.add_another_container.name }} {% endmacro %} {% macro collection_question_confirm_remove(runner) %} {% set question = runner.linked_question %} {% set existing_file_upload_answer = runner.submission.cached_get_answer_for_question(question.id, add_another_index=runner.add_another_index if runner.add_another_index is not none else none) %}