blob: 39308ceaaf336815b511133728aef42dda828681 [file] [log] [blame]
Dixsie Wolmersb34349d2021-11-02 22:06:35 -05001<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"
Surya Vde23ea22024-07-11 15:19:46 +053019 :state="getValidationState(v$.form.staticDns)"
20 @input="v$.form.staticDns.$touch()"
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050021 />
22 <b-form-invalid-feedback role="alert">
Surya Venkatesan4626aec2024-09-19 15:06:49 +053023 <template v-if="v$.form.staticDns.required.$invalid">
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050024 {{ $t('global.form.fieldRequired') }}
25 </template>
Surya Venkatesan4626aec2024-09-19 15:06:49 +053026 <template v-if="v$.form.staticDns.ipAddress.$invalid">
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050027 {{ $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';
Ed Tanous7d6b44c2024-03-23 14:56:34 -070047import { useVuelidate } from '@vuelidate/core';
48
49import { ipAddress, required } from '@vuelidate/validators';
Surya Vde23ea22024-07-11 15:19:46 +053050import { useI18n } from 'vue-i18n';
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050051
52export default {
53 mixins: [VuelidateMixin],
Hariharan Rangasamyc5d60f52025-10-31 12:58:56 +053054 emits: ['ok', 'hidden'],
Ed Tanous7d6b44c2024-03-23 14:56:34 -070055 setup() {
56 return {
57 v$: useVuelidate(),
58 };
59 },
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050060 data() {
61 return {
Surya Vde23ea22024-07-11 15:19:46 +053062 $t: useI18n().t,
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050063 form: {
64 staticDns: null,
65 },
66 };
67 },
68 validations() {
69 return {
70 form: {
71 staticDns: {
72 required,
73 ipAddress,
74 },
75 },
76 };
77 },
78 methods: {
79 handleSubmit() {
Surya Vde23ea22024-07-11 15:19:46 +053080 this.v$.$touch();
81 if (this.v$.$invalid) return;
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050082 this.$emit('ok', [this.form.staticDns]);
83 this.closeModal();
84 },
85 closeModal() {
86 this.$nextTick(() => {
87 this.$refs.modal.hide();
88 });
89 },
90 resetForm() {
91 this.form.staticDns = null;
Surya Vde23ea22024-07-11 15:19:46 +053092 this.v$.$reset();
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050093 this.$emit('hidden');
94 },
95 onOk(bvModalEvt) {
96 // prevent modal close
97 bvModalEvt.preventDefault();
98 this.handleSubmit();
99 },
100 },
101};
102</script>