blob: d9e98305bd1d14f21fe322ac91fce463d35c83d4 [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>
jason westoverd36ac8a2025-11-03 20:58:59 -060034 <template #footer="{ cancel }">
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050035 <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],
jason westoverd36ac8a2025-11-03 20:58:59 -060054 props: {
55 modelValue: {
56 type: Boolean,
57 default: false,
58 },
59 },
60 emits: ['ok', 'hidden', 'update:modelValue'],
Ed Tanous7d6b44c2024-03-23 14:56:34 -070061 setup() {
62 return {
63 v$: useVuelidate(),
64 };
65 },
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050066 data() {
67 return {
Surya Vde23ea22024-07-11 15:19:46 +053068 $t: useI18n().t,
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050069 form: {
70 staticDns: null,
71 },
72 };
73 },
74 validations() {
75 return {
76 form: {
77 staticDns: {
78 required,
79 ipAddress,
80 },
81 },
82 };
83 },
jason westoverd36ac8a2025-11-03 20:58:59 -060084 watch: {
85 modelValue: {
86 handler(newValue) {
87 if (newValue) {
88 this.$nextTick(() => {
89 this.$refs.modal?.show();
90 });
91 }
92 },
93 immediate: true,
94 },
95 },
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050096 methods: {
97 handleSubmit() {
Surya Vde23ea22024-07-11 15:19:46 +053098 this.v$.$touch();
99 if (this.v$.$invalid) return;
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500100 this.$emit('ok', [this.form.staticDns]);
101 this.closeModal();
102 },
103 closeModal() {
104 this.$nextTick(() => {
105 this.$refs.modal.hide();
106 });
107 },
108 resetForm() {
109 this.form.staticDns = null;
Surya Vde23ea22024-07-11 15:19:46 +0530110 this.v$.$reset();
jason westoverd36ac8a2025-11-03 20:58:59 -0600111 this.$emit('update:modelValue', false);
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500112 this.$emit('hidden');
113 },
114 onOk(bvModalEvt) {
115 // prevent modal close
116 bvModalEvt.preventDefault();
117 this.handleSubmit();
118 },
119 },
120};
121</script>