|
6 | 6 | </label> |
7 | 7 |
|
8 | 8 | <div class="field-wrap"> |
9 | | - <component ref="child" :is="fieldType" :model="model" :schema="field" :formOptions="options" :eventBus="eventBus" :fieldID="fieldID" @errors-updated="onChildValidated"></component> |
| 9 | + <component ref="child" :is="fieldType" :model="model" :schema="field" :formOptions="options" :eventBus="eventBus" :fieldID="fieldID" @field-touched="onFieldTouched" @errors-updated="onChildValidated"></component> |
10 | 10 | <div v-if="buttonsAreVisible" class="buttons"> |
11 | 11 | <button v-for="(btn, index) in field.buttons" @click="buttonClickHandler(btn, field, $event)" :class="btn.classes" :key="index" v-text="btn.label"></button> |
12 | 12 | </div> |
@@ -51,7 +51,8 @@ export default { |
51 | 51 | }, |
52 | 52 | data() { |
53 | 53 | return { |
54 | | - childErrors: [] |
| 54 | + childErrors: [], |
| 55 | + childTouched: false |
55 | 56 | }; |
56 | 57 | }, |
57 | 58 | computed: { |
@@ -84,7 +85,8 @@ export default { |
84 | 85 | fieldRowClasses() { |
85 | 86 | let baseClasses = { |
86 | 87 | [objGet(this.options, "validationErrorClass", "error")]: this.fieldHasErrors, |
87 | | - [objGet(this.options, "validationSuccessClass", "valid")]: !this.fieldHasErrors, |
| 88 | + [objGet(this.options, "validationSuccessClass", "valid")]: !this.fieldHasErrors && this.childTouched, |
| 89 | + [objGet(this.options, "validationCleanClass", "clean")]: !this.fieldHasErrors && !this.childTouched, |
88 | 90 | disabled: this.getValueFromOption(this.field, "disabled"), |
89 | 91 | readonly: this.getValueFromOption(this.field, "readonly"), |
90 | 92 | featured: this.getValueFromOption(this.field, "featured"), |
@@ -119,6 +121,9 @@ export default { |
119 | 121 | buttonClickHandler(btn, field, event) { |
120 | 122 | return btn.onclick.call(this, this.model, field, event, this); |
121 | 123 | }, |
| 124 | + onFieldTouched() { |
| 125 | + this.childTouched = true; |
| 126 | + }, |
122 | 127 | onChildValidated(errors) { |
123 | 128 | this.childErrors = errors; |
124 | 129 | } |
|
0 commit comments