blob: 83c1406a108d01afbbcf1a2e2a6964a3bd38e11f [file] [log] [blame]
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -06001<template>
2 <b-modal
3 id="modal-mac-address"
4 ref="modal"
5 :title="$t('pageNetwork.modal.editMacAddressTitle')"
6 @hidden="resetForm"
7 >
8 <b-form id="mac-settings" @submit.prevent="handleSubmit">
9 <b-row>
10 <b-col sm="6">
11 <b-form-group
12 :label="$t('pageNetwork.macAddress')"
13 label-for="macAddress"
14 >
15 <b-form-input
16 id="mac-address"
17 v-model.trim="form.macAddress"
18 data-test-id="network-input-macAddress"
19 type="text"
Surya Vde23ea22024-07-11 15:19:46 +053020 :state="getValidationState(v$.form.macAddress)"
21 @change="v$.form.macAddress.$touch()"
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060022 />
23 <b-form-invalid-feedback role="alert">
Surya Venkatesan4626aec2024-09-19 15:06:49 +053024 <div v-if="v$.form.macAddress.required.$invalid">
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060025 {{ $t('global.form.fieldRequired') }}
26 </div>
Surya Venkatesan4626aec2024-09-19 15:06:49 +053027 <div v-if="v$.form.macAddress.macAddress.$invalid">
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060028 {{ $t('global.form.invalidFormat') }}
29 </div>
30 </b-form-invalid-feedback>
31 </b-form-group>
32 </b-col>
33 </b-row>
34 </b-form>
35 <template #modal-footer="{ cancel }">
36 <b-button variant="secondary" @click="cancel()">
37 {{ $t('global.action.cancel') }}
38 </b-button>
39 <b-button
40 form="mac-settings"
41 type="submit"
42 variant="primary"
43 @click="onOk"
44 >
45 {{ $t('global.action.add') }}
46 </b-button>
47 </template>
48 </b-modal>
49</template>
50
51<script>
52import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -070053import { useVuelidate } from '@vuelidate/core';
Surya Venkatesan4626aec2024-09-19 15:06:49 +053054import { required } from '@vuelidate/validators';
55import { macAddress } from 'vuelidate/lib/validators';
Surya Vde23ea22024-07-11 15:19:46 +053056import { useI18n } from 'vue-i18n';
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060057
58export default {
59 mixins: [VuelidateMixin],
60 props: {
61 macAddress: {
62 type: String,
63 default: '',
64 },
65 },
Hariharan Rangasamyc5d60f52025-10-31 12:58:56 +053066 emits: ['ok', 'hidden'],
Ed Tanous7d6b44c2024-03-23 14:56:34 -070067 setup() {
68 return {
69 v$: useVuelidate(),
70 };
71 },
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060072 data() {
73 return {
Surya Vde23ea22024-07-11 15:19:46 +053074 $t: useI18n().t,
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060075 form: {
76 macAddress: '',
77 },
78 };
79 },
80 watch: {
81 macAddress() {
82 this.form.macAddress = this.macAddress;
83 },
84 },
85 validations() {
86 return {
87 form: {
88 macAddress: {
89 required,
90 macAddress: macAddress(),
91 },
92 },
93 };
94 },
95 methods: {
96 handleSubmit() {
Surya Vde23ea22024-07-11 15:19:46 +053097 this.v$.$touch();
98 if (this.v$.$invalid) return;
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060099 this.$emit('ok', { MACAddress: this.form.macAddress });
100 this.closeModal();
101 },
102 closeModal() {
103 this.$nextTick(() => {
104 this.$refs.modal.hide();
105 });
106 },
107 resetForm() {
108 this.form.macAddress = this.macAddress;
Surya Vde23ea22024-07-11 15:19:46 +0530109 this.v$.$reset();
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -0600110 this.$emit('hidden');
111 },
112 onOk(bvModalEvt) {
113 // prevent modal close
114 bvModalEvt.preventDefault();
115 this.handleSubmit();
116 },
117 },
118};
119</script>