Skip to content

Commit

Permalink
fix validation error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
eisfeuer committed Oct 16, 2020
1 parent 64b86c5 commit 349bbe8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

50 changes: 35 additions & 15 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<template>
<default-field
:field="field"
:errors="errors"
:show-help-text="showHelpText"
class="pb-0"
>
Expand All @@ -26,21 +25,23 @@
:for="getFieldId(fieldKey)"
class="inline-block text-80 leading-tight mb-1"
>{{ fieldProps.label }}</label>
<input
:id="getFieldId(fieldKey)"
v-model="value[fieldKey]"
type="text"
class="w-full form-control form-input form-input-bordered mb-3"
:class="errorClasses"
:placeholder="fieldProps.label"
>
<div class="mb-3">
<input
:id="getFieldId(fieldKey)"
v-model="value[fieldKey]"
type="text"
class="w-full form-control form-input form-input-bordered"
:class="hasAddressError(fieldKey) ? errorClasses : []"
:placeholder="fieldProps.label"
>
<div
v-if="hasAddressError(fieldKey)"
class="help-text error-text mt-2 text-danger"
>
{{ addressErrors[fieldKey][0] }}
</div>
</div>
</div>
<p
v-if="hasError"
class="my-2 text-danger"
>
{{ firstError }}
</p>
</template>
</default-field>
</template>
Expand All @@ -67,6 +68,15 @@ export default {
required: true
}
},
computed: {
addressErrors () {
if (!this.hasError) {
return {}
}
return JSON.parse(this.firstError)
}
},
methods: {
getFieldId (fieldKey) {
return this.field.name + ' ' + fieldKey
Expand All @@ -85,6 +95,16 @@ export default {
Nova.$emit(this.field.longitude + '-value', longitude)
},
hasAddressError (fieldKey) {
if (!Object.prototype.hasOwnProperty.call(this.addressErrors, fieldKey)) {
return false
}
const errors = this.addressErrors[fieldKey]
return Array.isArray(errors) && errors.length > 0
},
/*
* Set the initial, internal value for the field.
*/
Expand Down

0 comments on commit 349bbe8

Please sign in to comment.