control error display for options input component
This commit is contained in:
dandds 2018-11-08 11:43:29 -05:00 committed by GitHub
commit b661c7ce4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 13 deletions

View File

@ -2,15 +2,33 @@ export default {
name: 'optionsinput',
props: {
name: String
name: String,
initialErrors: {
type: Array,
default: () => []
},
initialValue: String,
},
data: function () {
const showError = (this.initialErrors && this.initialErrors.length) || false
return {
showError: showError,
showValid: !showError && !!this.initialValue,
validationError: this.initialErrors.join(' ')
}
},
methods: {
onInput: function (e) {
this.$root.$emit('field-change', {
value: e.target.value,
name: this.name
})
this.showError = false
this.showValid = true
}
}
}

View File

@ -46,13 +46,13 @@
fieldset {
input[type='radio'] {
+ label::before {
box-shadow: 0 0 0 1px $color-white, 0 0 0 3px $color-red;
box-shadow: 0 0 0 1px $color-white, 0 0 0 3px $state-color;
}
}
input[type='checkbox'] {
+ label::before {
box-shadow: 0 0 0 2px $color-red;
box-shadow: 0 0 0 2px $state-color;
}
}
}

View File

@ -2,8 +2,14 @@
{% from "components/tooltip.html" import Tooltip %}
{% macro OptionsInput(field, tooltip, inline=False) -%}
<optionsinput name='{{ field.name }}' inline-template key='{{ field.name }}'>
<div class='usa-input {% if field.errors %}usa-input--error{% endif %}'>
<optionsinput
name='{{ field.name }}'
inline-template
{% if field.errors %}v-bind:initial-errors='{{ field.errors | list }}'{% endif %}
{% if field.data and field.data != "None" %}v-bind:initial-value="'{{ field.data }}'"{% endif %}
key='{{ field.name }}'>
<div
v-bind:class="['usa-input', { 'usa-input--error': showError, 'usa-input--success': showValid }]">
<fieldset v-on:change="onInput" class="usa-input__choices {% if inline %}usa-input__choices--inline{% endif %}">
<legend>
@ -16,18 +22,15 @@
<span class='usa-input__help'>{{ field.description | safe }}</span>
{% endif %}
{% if field.errors %}
{{ Icon('alert',classes="icon-validation") }}
{% endif %}
<span v-show='showError'>{{ Icon('alert',classes="icon-validation") }}</span>
<span v-show='showValid'>{{ Icon('ok',classes="icon-validation") }}</span>
</legend>
{{ field() }}
{% if field.errors %}
{% for error in field.errors %}
<span class='usa-input__message'>{{ error }}</span>
{% endfor %}
{% endif %}
<template v-if='showError'>
<span class='usa-input__message' v-html='validationError'></span>
</template>
</fieldset>
</div>