Skip to content

Commit

Permalink
Merge pull request #151 from vrk-kpa/REKDAT-67_fix_missing_input_desc…
Browse files Browse the repository at this point in the history
…ription

REKDAT-67: fix missing input descriptions
  • Loading branch information
Zharktas authored Dec 22, 2023
2 parents 4b0dcaa + db1ef4c commit 395155a
Show file tree
Hide file tree
Showing 27 changed files with 466 additions and 436 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"fi",
"sv"
],
"description": "Give a short and descriptive name for the dataset.<br><br>The URL is created automatically based on the dataset title. You can edit the URL if you want.",
"description": "Give a short and descriptive name for the dataset.<br><br>The URL is created automatically based on the dataset title. If necessary, you can edit the URL.",
"group_title": "Dataset title",
"group_description": "* Required field"
},
Expand Down Expand Up @@ -46,7 +46,7 @@
"fi",
"sv"
],
"description": "Describe the dataset's contents, collection process, quality and possible limits, flaws and applications in a comprehensible way. Use as confining terms as possible to make it easier to find and understand the data.",
"description": "Describe the datasets contents, collection process, quality of the data and possible limits, flaws and applications in an easily understandable way.",
"group_title": "Dataset description"
},
{
Expand All @@ -71,7 +71,7 @@
"data-module-source": "/api/2/util/tag/autocomplete?incomplete=?&vocabulary_id=keywords"
},
"group_title": "Keywords and categories",
"description": "Keywords help users to find your data. Select at least one keyword in Finnish and Swedish."
"description": "Select at least one keyword relating to your data that helps users to find your data."
},
{
"field_name": "categories",
Expand All @@ -89,7 +89,7 @@
"display_snippet": "license.html",
"validators": "not_empty",
"required": true,
"description": "Select a license that suits your needs. We recommend using CC0 or CC BY 4 -licenses.",
"description": "Select a license that suits your needs.",
"group_title": "Dataset additional information"
},
{
Expand Down Expand Up @@ -148,6 +148,7 @@
],
"default_value": "non-public",
"validators": "keep_old_value_if_missing",
"description": "Select access rights for your dataset:<br><br><b>Non-public</b> datasets may include resources that contain sensitive or personal information.<br><br><b>Restricted</b> datasets may include resources that require payment, resources shared under non-disclosure agreements, resources for which the publisher or owner has not yet decided if they can be publicly released.",
"required": true
},
{
Expand Down Expand Up @@ -277,7 +278,7 @@
"form_attrs": {
"class": "form-control"
},
"description": "Write a short and descriptive name for the data resource. If the data covers a specific time frame, mention that in the name.",
"description": "Give a short and descriptive name for the distribution. If the data covers a specific time frame, mention that in the name.",
"group_title": "Data resource title",
"group_description": "* Required field"
},
Expand All @@ -290,13 +291,13 @@
"validators": "unicode_safe remove_whitespace not_empty url_validator",
"upload_label": "Resource URL",
"group_title": "Resource *",
"group_description": "Add the data resource by adding a link to the data."
"group_description": "Add the distribution by adding a link to the data."
},
{
"field_name": "format",
"label": "Format",
"preset": "resource_format_autocomplete",
"description": "File format of the selected resource.",
"description": "Select a file format for the distribution",
"validators": "if_empty_guess_format clean_format unicode_safe not_empty ",
"required": true
},
Expand All @@ -307,7 +308,7 @@
},
"label": "Size",
"required": true,
"description": "Size of the added resource file in bytes. Will be automatically filled when the file is uploaded.",
"description": "Enter the file size in bytes.\n\nThe size can be approximated as a decimal if the precise size is not known. If data is offered via an API, enter the overall size of the underlying data.",
"validators": "not_empty int_validator"
},
{
Expand All @@ -332,6 +333,7 @@
"label": "Conditions for re-use",
"preset": "fluent_markdown_editor",
"validators": "fluent_text required_languages",
"description": "Describe terms and conditions for re-use. Include how to apply for use permit and information about possible payments and their principles.",
"form_placeholder": "Write a rights statement for the resource",
"form_languages": [
"fi",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% from "macros/form/input_block.html" import input_block %}
{% from "macros/form/attributes.html" import attributes %}

{#
ADDED DESCRIPTION PROPERTY
Creates all the markup required for an input element. Handles matching labels to
inputs, error messages and other useful elements.

name - The name of the form parameter.
id - The id to use on the input and label. Convention is to prefix with 'field-'.
label - The human readable label.
value - The value of the input.
placeholder - Some placeholder text.
type - The type of input eg. email, url, date (default: text).
error - A list of error strings for the field or just true to highlight the field.
classes - An array of classes to apply to the form-group.
is_required - Boolean of whether this input is requred for the form to validate
description - Additional description text between the label and the input
#}



{% macro input(name, id='', label='', value='', placeholder='', type='text', error="", classes=[], attrs={'class': 'form-control'}, is_required=false, description="") %}
{%- set extra_html = caller() if caller -%}
{% call input_block(id or name, label or name, error, classes, extra_html=extra_html, is_required=is_required, description=description) %}
<input id="{{ id or name }}" type="{{ type }}" name="{{ name }}" value="{{ value | empty_and_escape }}" placeholder="{{ placeholder }}" {{ attributes(attrs) }} />
{% endcall %}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{#
ADDED DESCRIPTION PROPERTY
A generic input_block for providing the default markup for CKAN form elements.
It is expected to be called using a {% call %} block, the contents of which
will be inserted into the .controls element.
Expand All @@ -10,6 +11,7 @@
control_classes - An array of custom classes for the .control wrapper.
extra_html - An html string to be inserted after the errors eg. info text.
is_required - Boolean of whether this input is requred for the form to validate
description - Additional description text between the label and the input

Example:

Expand All @@ -20,16 +22,17 @@

#}

{% macro input_block(for, label="", error="", classes=[], control_classes=[], extra_html="", is_required=false) %}
{% macro input_block(for, label="", error="", classes=[], control_classes=[], extra_html="", is_required=false, description="") %}
<div class="form-group{{ " error" if error }}{{ " " ~ classes | join(" ") }}">
<label class="form-label" for="{{ for }}">
{{ label or _("Custom") }}
{% if is_required %}<span title="{{ _("This field is required") }}" class="control-required">*</span>{% endif %}
</label>
<div class="controls{{ " " ~ control_classes | join(" ") }}">
{% if description and description.strip() %}<div class="field-description-text">{{ _(description) }}</div>{% endif %}
<div class="controls{{- ' ' ~ control_classes | join(" ") -}}">
{{ caller() }}
{% if error and error is iterable %}<span class="error-block">{{ error|join(", ") }}</span>{% endif %}
{{ extra_html }}
</div>
</div>
</div>
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% from "macros/form/input_block.html" import input_block %}
{% from "macros/form/attributes.html" import attributes %}

{% macro input_multiple(name, id='', label='', value='', placeholder='', type='text', error="", classes=[], attrs={}, is_required=false, description="") %}
{% asset 'registrydata/form-js' %}
{% do classes.append('control-medium') %}
{%- set extra_html = caller() if caller -%}
{% call input_block(id or name, label or name, error, classes, control_classes=["editor"], extra_html=extra_html, is_required=is_required, description="") %}
<div class="multiple-values">
{% if value and value != [''] %}
{% set values = value if value.append else [value] %}
{% for value_item in values %}
{% if value_item %}
<div class="multiple-value-group">
<input id="{{ id or name }}-{{ loop.index }}" type="{{ type }}" name="{{ name }}" value="{{ value_item | empty_and_escape }}" placeholder="{{ placeholder }}" class="multiple-value form-control" {{ form.attributes(attrs) }} />
</div>
{% endif %}
{% endfor %}
{% else %}
<div class="multiple-value-group">
<input id="{{ id or name }}" type="{{ type }}" name="{{ name }}" value="" placeholder="{{ placeholder }}" class="multiple-value form-control" {{ attributes(attrs) }} />
</div>
{% endif %}
</div>
{% endcall %}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{% from "macros/form/input_block.html" import input_block %}
{% from "macros/form/attributes.html" import attributes %}


{#
Creates all the markup required for a Markdown textarea element. Handles
matching labels to inputs, selected item and error messages.

name - The name of the form parameter.
id - The id to use on the input and label. Convention is to prefix with 'field-'.
label - The human readable label.
value - The value of the input.
placeholder - Some placeholder text.
error - A list of error strings for the field or just true to highlight the field.
classes - An array of classes to apply to the form-group.
is_required - Boolean of whether this input is requred for the form to validate

Examples:

{% import 'macros/form.html' as form %}
{{ form.markdown('desc', id='field-description', label=_('Description'), value=data.desc, error=errors.desc) }}

#}


{% macro markdown(name, id='', label='', value='', placeholder='', error="", classes=[], attrs={'class': 'form-control'}, is_required=false, description=None) %}
{% set classes = (classes|list) %}
{% do classes.append('control-full') %}
{% set markdown_tooltip = '<pre><p>__Bold text__ or _italic text_</p><p># title<br>## secondary title<br>### etc</p><p>* list<br>* of<br>* items</p><p>http://auto.link.ed/</p></pre><p><b><a href="https://daringfireball.net/projects/markdown/syntax"
target="_blank">Full markdown syntax</a></b></p><p class="text-muted"><b>Please note:</b> HTML tags are stripped out for security reasons</p>' %}

{%- set extra_html = caller() if caller -%}
{% call input_block(id or name, label or name, error, classes, control_classes=["editor"], extra_html=extra_html, is_required=is_required, description=description) %}
<textarea id="{{ id or name }}" name="{{ name }}" cols="20" rows="5" placeholder="{{ placeholder }}" {{ form.attributes(attrs) }}>{{ value | empty_and_escape }}</textarea>
<span class="editor-info-block">{% trans %}You can use <a href="#markdown"
title="Markdown quick reference"
data-bs-toggle="popover"
data-bs-trigger="focus"
data-bs-content="{{ markdown_tooltip }}"
data-bs-html="true">Markdown formatting</a> here{% endtrans %}</span>
{% endcall %}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% from "macros/form/input_block.html" import input_block %}
{% from "macros/form/attributes.html" import attributes %}

{#
ADDED DESCRIPTION PROPERTY
Creates all the markup required for an input element with a prefixed segment.
These are useful for showing url slugs and other fields where the input
information forms only part of the saved data.

name - The name of the form parameter.
id - The id to use on the input and label. Convention is to prefix with 'field-'.
label - The human readable label.
prepend - The text that will be prepended before the input.
value - The value of the input.
which will use the name key as the value.
placeholder - Some placeholder text.
error - A list of error strings for the field or just true to highlight the field.
classes - An array of classes to apply to the form-group.
is_required - Boolean of whether this input is requred for the form to validate

Examples:

{% import 'macros/form.html' as form %}
{{ form.prepend('slug', id='field-slug', prepend='/dataset/', label=_('Slug'), value=data.slug, error=errors.slug) }}

#}
{% macro prepend(name, id='', label='', prepend='', value='', placeholder='', type='text', error="", classes=[], attrs={'class': 'form-control'}, is_required=false, description='') %}
{# We manually append the error here as it needs to be inside the .input-group block #}
{% set classes = (classes|list) %}
{% do classes.append('error') if error %}
{%- set extra_html = caller() if caller -%}
{% call input_block(id or name, label or name, error='', classes=classes, extra_html=extra_html, is_required=is_required, description=description) %}
<div class="input-group">
{% if prepend %}
<label class="input-group-text">{{ prepend }}</label>
{%- endif -%}
<input id="{{ id or name }}" type="{{ type }}" name="{{ name }}" value="{{ value | empty_and_escape }}" placeholder="{{ placeholder }}" {{ attributes(attrs) }} />
{% if error and error is iterable %}<span class="error-block">{{ error|join(", ") }}</span>{% endif %}
</div>
{% endcall %}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{% from "macros/form/input_block.html" import input_block %}
{% from "macros/form/attributes.html" import attributes %}

{#
ADDED DESCRIPTION PROPERTY
Creates all the markup required for an select element. Handles matching labels to
inputs and error messages.

A field should be a dict with a "value" key and an optional "text" key which
will be displayed to the user. We use a dict to easily allow extension in
future should extra options be required.

name - The name of the form parameter.
id - The id to use on the input and label. Convention is to prefix with 'field-'.
label - The human readable label.
description - Additional description text between the label and the input
options - A list/tuple of fields to be used as <options>.
selected - The value of the selected <option>.
error - A list of error strings for the field or just true to highlight the field.
classes - An array of classes to apply to the form-group.
is_required - Boolean of whether this input is requred for the form to validate

Examples:

{% import 'macros/form.html' as form %}
{{ form.select('year', label=_('Year'), options=[{'name':2010, 'value': 2010},{'name': 2011, 'value': 2011}], selected=2011, error=errors.year) }}

#}
{% macro select(name, id='', label='', options='', selected='', error='', classes=[], attrs={'class': 'form-control'}, is_required=false, description='') %}
{% set classes = (classes|list) %}
{% do classes.append('control-select') %}

{%- set extra_html = caller() if caller -%}
{% call input_block(id or name, label or name, error, classes, extra_html=extra_html, is_required=is_required, description=description) %}
<select id="{{ id or name }}" name="{{ name }}" {{ attributes(attrs) }}>
{% for option in options %}
<option value="{{ option.value }}"
{% if option.value == selected %}selected{% endif %}>{{ option.text or option.value }}</option>
{% endfor %}
</select>
{% endcall %}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{% from "macros/form/input_block.html" import input_block %}
{% from "macros/form/attributes.html" import attributes %}

{#
ADDED DESCRIPTION PROPERTY
Creates all the markup required for a plain textarea element. Handles
matching labels to inputs, selected item and error messages.

name - The name of the form parameter.
id - The id to use on the input and label. Convention is to prefix with 'field-'.
label - The human readable label.
description - Additional description text between the label and the input
value - The value of the input.
placeholder - Some placeholder text.
error - A list of error strings for the field or just true to highlight the field.
classes - An array of classes to apply to the form-group.
is_required - Boolean of whether this input is requred for the form to validate

Examples:

{% import 'macros/form.html' as form %}
{{ form.textarea('desc', id='field-description', label=_('Description'), value=data.desc, error=errors.desc) }}

#}


{% macro textarea(name, id='', label='', value='', placeholder='', error="", classes=[], attrs={'class': 'form-control'}, is_required=false, rows=5, cols=20, description='') %}
{% set classes = (classes|list) %}
{% do classes.append('control-full') %}

{%- set extra_html = caller() if caller -%}
{% call input_block(id or name, label or name, error, classes, extra_html=extra_html, is_required=is_required, description=description) %}
<textarea id="{{ id or name }}" name="{{ name }}" cols="{{ cols }}" rows="{{ rows }}" placeholder="{{ placeholder }}" {{ attributes(attrs) }}>{{ value | empty_and_escape }}</textarea>
{% endcall %}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% import 'macros/form.html' as form %}
{% import 'scheming/macros/form.html' as scheming_form %}
{% from 'macros/form/input_block.html' import input_block %}

{# this snippet is meant to be called from organization.html,
not used as a form_snippet directly #}
Expand All @@ -9,7 +9,7 @@
{% set description = field.description %}
{% endif %}
{% set existing_org = data.owner_org or data.group_id %}
{% call scheming_form.input_block('field-organizations',
{% call input_block('field-organizations',
label=h.scheming_language_text(field.label),
error=errors[field.field_name],
is_required=org_required,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% import 'scheming/macros/form.html' as form %}
{% from 'macros/form/textarea.html' import textarea %}

{% asset 'markdown_editor/markdown_editor-js' %}

Expand All @@ -8,7 +8,7 @@
{% endif %}
{% set form_attrs = {'data-module': 'ckeditor5-markdown', 'data-module-language': h.get_lang_prefix()} %}
{% do form_attrs.update(field.form_attrs or {}) %}
{% call form.textarea(
{% call textarea(
field.field_name + '-' + lang,
id='field-' + field.field_name + '-' + lang,
label=_(field.label) + ' ' + _(lang),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{% import 'scheming/macros/form.html' as form %}
{% from 'macros/form/markdown.html' import markdown %}

<div class="form-group-fluent control-group">
{%- for lang in h.fluent_form_languages(field, entity_type, object_type, schema) -%}
{% if loop.first and field.description and field.description.strip() %}
{% set description = field.description %}
{% endif %}
{% call form.markdown(
{% call markdown(
field.field_name + '-' + lang,
id='field-' + field.field_name + '-' + lang,
label=_(field.label) + ' ' + _(lang|upper),
Expand Down
Loading

0 comments on commit 395155a

Please sign in to comment.