blob: 179d831fa499b26796c6db2f15bffada42b5f761 [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],
Ed Tanous7d6b44c2024-03-23 14:56:34 -070054 setup() {
55 return {
56 v$: useVuelidate(),
57 };
58 },
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050059 data() {
60 return {
Surya Vde23ea22024-07-11 15:19:46 +053061 $t: useI18n().t,
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050062 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() {
Surya Vde23ea22024-07-11 15:19:46 +053079 this.v$.$touch();
80 if (this.v$.$invalid) return;
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050081 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;
Surya Vde23ea22024-07-11 15:19:46 +053091 this.v$.$reset();
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050092 this.$emit('hidden');
93 },
94 onOk(bvModalEvt) {
95 // prevent modal close
96 bvModalEvt.preventDefault();
97 this.handleSubmit();
98 },
99 },
100};
101</script>