From 89e613d44557233b75eddeadf2d1ee346a2dd523 Mon Sep 17 00:00:00 2001 From: dandds Date: Tue, 6 Nov 2018 15:27:42 -0500 Subject: [PATCH] control error display for options input component --- js/components/options_input.js | 18 +++++++++++++++++- styles/elements/_inputs.scss | 4 ++-- templates/components/options_input.html | 22 ++++++++++++---------- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/js/components/options_input.js b/js/components/options_input.js index eb16f706..5c965bd7 100644 --- a/js/components/options_input.js +++ b/js/components/options_input.js @@ -2,15 +2,31 @@ export default { name: 'optionsinput', props: { - name: String + name: String, + initialErrors: { + type: Array, + default: () => [] + }, }, + + data: function () { + return { + showError: (this.initialErrors && this.initialErrors.length) || false, + showValid: false, + 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 } } } diff --git a/styles/elements/_inputs.scss b/styles/elements/_inputs.scss index 2be9f2fe..d1cf89eb 100644 --- a/styles/elements/_inputs.scss +++ b/styles/elements/_inputs.scss @@ -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; } } } diff --git a/templates/components/options_input.html b/templates/components/options_input.html index 34c9a0da..0c3bd36a 100644 --- a/templates/components/options_input.html +++ b/templates/components/options_input.html @@ -2,8 +2,13 @@ {% from "components/tooltip.html" import Tooltip %} {% macro OptionsInput(field, tooltip, inline=False) -%} - -
+ +
@@ -16,18 +21,15 @@ {{ field.description | safe }} {% endif %} - {% if field.errors %} - {{ Icon('alert',classes="icon-validation") }} - {% endif %} + {{ Icon('alert',classes="icon-validation") }} + {{ Icon('ok',classes="icon-validation") }} {{ field() }} - {% if field.errors %} - {% for error in field.errors %} - {{ error }} - {% endfor %} - {% endif %} +