{# Copyright 2021, 2022 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. #} {% macro input(label, name, type="text", form_state=false, autocomplete=false, class="", inputmode="text", autocorrect=false, autocapitalize=false, disabled=false, required=false) %} {% if not form_state %} {% set form_state = dict(errors=[], fields=dict()) %} {% endif %} {% set state = form_state.fields[name] | default(value=dict(errors=[], value="")) %}
{{ label }}
{% if state.errors is not empty %} {% for error in state.errors %} {% if error.kind != "unspecified" %}
{% if error.kind == "required" %} This field is required {% elif error.kind == "exists" and name == "username" %} This username is already taken {% elif error.kind == "policy" %} Denied by policy: {{ error.message }} {% else %} {{ error.kind }} {% endif %}
{% endif %} {% endfor %} {% endif %}
{% endmacro input %}