1<template> 2 <b-modal 3 id="modal-dns" 4 ref="modal" 5 :title="$t('pageNetwork.table.addDnsAddress')" 6 @hidden="resetForm" 7 > 8 <b-form id="form-dns" @submit.prevent="handleSubmit"> 9 <b-row> 10 <b-col sm="6"> 11 <b-form-group 12 :label="$t('pageNetwork.modal.staticDns')" 13 label-for="staticDns" 14 > 15 <b-form-input 16 id="staticDns" 17 v-model="form.staticDns" 18 type="text" 19 :state="getValidationState(v$.form.staticDns)" 20 @input="v$.form.staticDns.$touch()" 21 /> 22 <b-form-invalid-feedback role="alert"> 23 <template v-if="v$.form.staticDns.required.$invalid"> 24 {{ $t('global.form.fieldRequired') }} 25 </template> 26 <template v-if="v$.form.staticDns.ipAddress.$invalid"> 27 {{ $t('global.form.invalidFormat') }} 28 </template> 29 </b-form-invalid-feedback> 30 </b-form-group> 31 </b-col> 32 </b-row> 33 </b-form> 34 <template #modal-footer="{ cancel }"> 35 <b-button variant="secondary" @click="cancel()"> 36 {{ $t('global.action.cancel') }} 37 </b-button> 38 <b-button form="form-dns" type="submit" variant="primary" @click="onOk"> 39 {{ $t('global.action.add') }} 40 </b-button> 41 </template> 42 </b-modal> 43</template> 44 45<script> 46import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js'; 47import { useVuelidate } from '@vuelidate/core'; 48 49import { ipAddress, required } from '@vuelidate/validators'; 50import { useI18n } from 'vue-i18n'; 51 52export default { 53 mixins: [VuelidateMixin], 54 setup() { 55 return { 56 v$: useVuelidate(), 57 }; 58 }, 59 data() { 60 return { 61 $t: useI18n().t, 62 form: { 63 staticDns: null, 64 }, 65 }; 66 }, 67 validations() { 68 return { 69 form: { 70 staticDns: { 71 required, 72 ipAddress, 73 }, 74 }, 75 }; 76 }, 77 methods: { 78 handleSubmit() { 79 this.v$.$touch(); 80 if (this.v$.$invalid) return; 81 this.$emit('ok', [this.form.staticDns]); 82 this.closeModal(); 83 }, 84 closeModal() { 85 this.$nextTick(() => { 86 this.$refs.modal.hide(); 87 }); 88 }, 89 resetForm() { 90 this.form.staticDns = null; 91 this.v$.$reset(); 92 this.$emit('hidden'); 93 }, 94 onOk(bvModalEvt) { 95 // prevent modal close 96 bvModalEvt.preventDefault(); 97 this.handleSubmit(); 98 }, 99 }, 100}; 101</script> 102