{% set maxChars = (field.limit and field.maxType == 'characters' and field.max) ? field.max : null %}
{% set maxWords = (field.limit and field.maxType == 'words' and field.max) ? field.max : null %}

{% if field.useRichText %}
    {{ fieldtag('fieldRichText') }}

    <div style="display: none !important;">
        {{ fieldtag('fieldInput', {
            text: value,
        }) }}
    </div>
{% else %}
    {{ fieldtag('fieldInput', {
        text: value,
    }) }}
{% endif %}

{% if field.limit %}
    {% if maxChars %}
        {% fieldtag 'fieldLimit' with {
            'data-limit': true,
            'data-max-chars': maxChars,
        } %}
            {{- '{startTag}{num}{endTag} characters left' | t('formie', {
                num: maxChars,
                startTag: '<span class="fui-limit-number">',
                endTag: '</span>',
            }) | raw -}}
        {% endfieldtag %}
    {% endif %}

    {% if maxWords %}
        {% fieldtag 'fieldLimit' with {
            'data-limit': true,
            'data-max-words': maxWords,
        } %}
            {{- '{startTag}{num}{endTag} words left' | t('formie', {
                num: maxWords,
                startTag: '<span class="fui-limit-number">',
                endTag: '</span>',
            }) | raw -}}
        {% endfieldtag %}
    {% endif %}
{% endif %}
