lesson 133: add my solution for an error dialog
This commit is contained in:
parent
c13912799a
commit
b6c7305492
|
@ -0,0 +1,18 @@
|
||||||
|
<template>
|
||||||
|
<dialog open>
|
||||||
|
<slot></slot>
|
||||||
|
</dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
dialog {
|
||||||
|
margin: 0;
|
||||||
|
position: fixed;
|
||||||
|
top: 20vh;
|
||||||
|
left: 30%;
|
||||||
|
width: 40%;
|
||||||
|
background-color: white;
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -23,19 +23,41 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</base-card>
|
</base-card>
|
||||||
|
<teleport to="body">
|
||||||
|
<error-alert v-if="inputIsInvalid">
|
||||||
|
<h2>Input may not be empty</h2>
|
||||||
|
<button @click="resetErrorDialog">Ok</button>
|
||||||
|
</error-alert>
|
||||||
|
</teleport>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import ErrorAlert from '../ErrorAlert';
|
||||||
export default {
|
export default {
|
||||||
|
components: {
|
||||||
|
ErrorAlert
|
||||||
|
},
|
||||||
inject: ['storeNewResource'],
|
inject: ['storeNewResource'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
title: '',
|
title: '',
|
||||||
description: '',
|
description: '',
|
||||||
link: ''
|
link: '',
|
||||||
|
inputIsInvalid: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
validateInput(resource) {
|
||||||
|
if (!resource.title || !resource.description || !resource.link) {
|
||||||
|
this.inputIsInvalid = true;
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
resetErrorDialog() {
|
||||||
|
this.inputIsInvalid = false;
|
||||||
|
},
|
||||||
returnNewResource() {
|
returnNewResource() {
|
||||||
const resource = {
|
const resource = {
|
||||||
id: new Date().toISOString(),
|
id: new Date().toISOString(),
|
||||||
|
@ -43,7 +65,9 @@ export default {
|
||||||
description: this.description,
|
description: this.description,
|
||||||
link: this.link
|
link: this.link
|
||||||
};
|
};
|
||||||
this.storeNewResource(resource);
|
if (this.validateInput(resource)) {
|
||||||
|
this.storeNewResource(resource);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Reference in New Issue