2020-04-09 21:57:57 +02:00
|
|
|
<template>
|
|
|
|
|
<div class="ui-error" v-if="visible">
|
2020-05-03 17:09:45 +02:00
|
|
|
<ui-message v-for="error in errors" :key="error.id" type="error" :text="error.message" :title="error.field" />
|
2020-04-09 21:57:57 +02:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2021-12-07 15:59:29 +01:00
|
|
|
import { generateId } from '../utils/numbers';
|
2020-04-09 21:57:57 +02:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'uiError',
|
|
|
|
|
|
|
|
|
|
props: {
|
2020-04-15 15:13:38 +02:00
|
|
|
field: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: ''
|
|
|
|
|
},
|
|
|
|
|
catchRemaining: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
},
|
|
|
|
|
catchAll: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
}
|
2020-04-09 21:57:57 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
data: () => ({
|
|
|
|
|
errors: []
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
mounted ()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
|
visible()
|
|
|
|
|
{
|
|
|
|
|
return this.errors && this.errors.length;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
|
|
|
|
// set and display errors
|
2020-09-09 13:43:01 +02:00
|
|
|
setErrors(errors, append)
|
2020-04-09 21:57:57 +02:00
|
|
|
{
|
2020-09-09 13:08:47 +02:00
|
|
|
if (!errors)
|
|
|
|
|
{
|
2020-09-09 13:43:01 +02:00
|
|
|
return this.clearErrors();
|
2020-09-09 13:08:47 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-07 15:59:29 +01:00
|
|
|
if (!Array.isArray(errors))
|
2020-04-09 21:57:57 +02:00
|
|
|
{
|
|
|
|
|
errors = [errors];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errors.forEach(error =>
|
|
|
|
|
{
|
2021-12-07 15:59:29 +01:00
|
|
|
error.id = generateId();
|
2020-04-09 21:57:57 +02:00
|
|
|
});
|
|
|
|
|
|
2020-09-09 13:08:47 +02:00
|
|
|
if (append)
|
|
|
|
|
{
|
|
|
|
|
errors.forEach(error =>
|
|
|
|
|
{
|
|
|
|
|
this.errors.push(error);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.errors = errors;
|
|
|
|
|
}
|
2020-04-09 21:57:57 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// clear errors and hide
|
2020-09-09 13:43:01 +02:00
|
|
|
clearErrors()
|
2020-04-09 21:57:57 +02:00
|
|
|
{
|
|
|
|
|
this.errors = [];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-23 10:58:14 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
.ui-error + .editor
|
|
|
|
|
{
|
|
|
|
|
margin-top: var(--padding-m);
|
|
|
|
|
}
|
|
|
|
|
</style>
|