110 lines
3.7 KiB
HTML
110 lines
3.7 KiB
HTML
---
|
|
base:
|
|
type: "string"
|
|
default: ""
|
|
schema:
|
|
type: "hash"
|
|
default_value_types:
|
|
type: "hash"
|
|
default_label_class_by_type:
|
|
type: "hash"
|
|
---
|
|
{% assign col = false %}
|
|
{% for field in schema %}
|
|
{% assign id = field[0] %}
|
|
{% assign type = field[1].type %}
|
|
{% assign required = field[1] | try: 'required' %}
|
|
{% assign name = field[1] | try: 'name' | default: id %}
|
|
{% unless base == empty %}
|
|
{% assign name = base | append: '[' | append: name | append: ']' %}
|
|
{% assign id = base | replace: '[', '_' | remove: ']' | append: '_' | append: id %}
|
|
{% endunless %}
|
|
{% assign template = 'forms/' | append: type | append: '.html' %}
|
|
{% assign default_values = field[1] | try: 'values', locale %}
|
|
{% assign depends_on = field[1] | try: 'depends_on' %}
|
|
{% assign dependents = field[1] | try: 'dependents' %}
|
|
{% assign attributes = '' %}
|
|
|
|
{% if type == 'end_row' %}
|
|
</div>
|
|
{% assign col = false %}
|
|
{% continue %}
|
|
{% endif %}
|
|
|
|
{% if type == 'row' %}
|
|
<div class="row">
|
|
{% assign col = true %}
|
|
{% continue %}
|
|
{% endif %}
|
|
|
|
{% if dependents %}
|
|
{% unless base == empty %}
|
|
{% capture dependents -%}
|
|
{%- for dependent in dependents -%}
|
|
{{- base | replace: '[', '_' | remove: ']' }}_{{ dependent }}{{ forloop.last | value_unless: ',' -}}
|
|
{%- endfor -%}
|
|
{%- endcapture %}
|
|
{% assign dependents = dependents | split: ',' %}
|
|
{% endunless %}
|
|
|
|
{% assign dependents = dependents | jsonify | escape %}
|
|
{% assign attributes = attributes
|
|
| append: ' '
|
|
| append: 'data-action="form-dependencies#update" data-form-dependencies-dependents-param="'
|
|
| append: dependents
|
|
| append: '"'
|
|
%}
|
|
{% endif %}
|
|
|
|
<div
|
|
class="mb-3{{ col | value_if: ' col' }}"
|
|
{% if depends_on %}
|
|
{% assign attributes = attributes | append: ' ' | append: 'disabled' %}
|
|
|
|
data-form-dependencies-target="dependent"
|
|
data-form-dependencies-dependent-id="{{ depends_on.id | escape_once }}"
|
|
data-form-dependencies-id="{{ id | escape_once }}"
|
|
data-form-dependencies-condition="{{ depends_on | try: 'condition' | default: 'any' | escape_once }}"
|
|
data-form-dependencies-value="{{ depends_on | try: 'value' | escape_once }}"
|
|
hidden
|
|
{% endif %}
|
|
>
|
|
{% if type == 'section' %}
|
|
{% block 'forms/section.html', id: %}
|
|
{{ field[1].label[locale] }}
|
|
{% endblock %}
|
|
</div>
|
|
{% continue %}
|
|
{% else %}
|
|
{% assign class = default_label_class_by_type | try: type %}
|
|
{% block 'forms/label.html', id:, class: %}
|
|
{{ field[1].label[locale] }}
|
|
{% endblock %}
|
|
{% endif %}
|
|
|
|
{% comment %}
|
|
We need to determine the default value type from the template
|
|
type, as defined on the schema.
|
|
|
|
Templates of the same default value type need to share the same
|
|
schema.
|
|
|
|
If there's an error thrown for this block, it probably means the
|
|
field type wasn't declared on the default_value_types hash.
|
|
{% endcomment %}
|
|
{% case default_value_types[type] %}
|
|
{% when 'array' %}
|
|
{% render template, required:, id:, name:, items: default_values, attributes: %}
|
|
{% when 'hash' %}
|
|
{% assign value = default_values | try: 'value' %}
|
|
{% assign item = default_values | try: 'item' | default: value %}
|
|
{% render template, required:, id:, name:, item:, value:, attributes: %}
|
|
{% when 'nested_form' %}
|
|
{% assign schema = field[1].schema %}
|
|
{% render template, schema:, default_value_types:, name:, default_label_class_by_type: %}
|
|
{% else %}
|
|
{% render template, required:, id:, name:, value: default_values, attributes: %}
|
|
{% endcase %}
|
|
</div>
|
|
{% endfor %}
|