Vue-ify text-input macro

This commit is contained in:
Andrew Croce 2018-08-08 14:40:58 -04:00
parent 1c4c49da62
commit c80490f717

View File

@ -1,5 +1,11 @@
{% macro TextInput(field, placeholder='') -%} {% from "components/icon.html" import Icon %}
<div class='usa-input {% if errors %}usa-input--error{% endif %}'>
{% macro TextInput(field, placeholder='', validation='anything', paragraph=False) -%}
<textinput name={{ field.name }} validation={{ validation }} inline-template {% if field.value %}value={{ field.value }}{% endif %}>
<div
class='usa-input {% if errors %}usa-input--error{% endif %}'
v-bind:class="['usa-input usa-input--validation--' + validation, { 'usa-input--error': showError, 'usa-input--success': showValid }]">
<label for={{field.name}}> <label for={{field.name}}>
{{ field.label }} {{ field.label }}
@ -10,9 +16,39 @@
{% if errors %} {% if errors %}
{{ Icon('alert') }} {{ Icon('alert') }}
{% endif %} {% endif %}
<template v-if='showError'>{{ Icon('alert') }}</template>
<template v-if='showValid'>{{ Icon('ok') }}</template>
</label> </label>
{{ field(placeholder=placeholder) | safe }} {% if paragraph %}
<textarea
v-on:input='onInput'
v-on:change='onChange'
v-model='renderedValue'
id='{{ field.name }}'
ref='input'
placeholder='{{ placeholder }}'>
</textarea>
{% else %}
<masked-input
v-on:input='onInput'
v-on:change='onChange'
v-model='renderedValue'
id='{{ field.name }}'
type='text'
ref='input'
placeholder='{{ placeholder }}'
:guide="true"
:mask="mask"
:pipe="pipe"
:keep-char-positions="keepCharPositions">
</masked-input>
{% endif %}
{% if field.errors %} {% if field.errors %}
{% for error in field.errors %} {% for error in field.errors %}
@ -20,4 +56,5 @@
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</div> </div>
</textinput>
{%- endmacro %} {%- endmacro %}