blob: eb20f17eddea606a6ff0066de0a185f79f4eeb61 [file] [log] [blame]
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -06001<template>
2 <b-modal
3 id="modal-hostname"
4 ref="modal"
5 :title="$t('pageNetwork.modal.editHostnameTitle')"
6 @hidden="resetForm"
7 >
8 <b-form id="hostname-settings" @submit.prevent="handleSubmit">
9 <b-row>
10 <b-col sm="6">
11 <b-form-group
12 :label="$t('pageNetwork.hostname')"
13 label-for="hostname"
14 >
15 <b-form-input
16 id="hostname"
17 v-model="form.hostname"
18 type="text"
Surya Vde23ea22024-07-11 15:19:46 +053019 :state="getValidationState(v$.form.hostname)"
20 @input="v$.form.hostname.$touch()"
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060021 />
22 <b-form-invalid-feedback role="alert">
Surya Venkatesan4626aec2024-09-19 15:06:49 +053023 <template v-if="v$.form.hostname.required.$invalid">
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060024 {{ $t('global.form.fieldRequired') }}
25 </template>
Surya Venkatesan4626aec2024-09-19 15:06:49 +053026 <template v-if="v$.form.hostname.validateHostname.$invalid">
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060027 {{ $t('global.form.lengthMustBeBetween', { min: 1, max: 64 }) }}
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
39 form="hostname-settings"
40 type="submit"
41 variant="primary"
42 @click="onOk"
43 >
44 {{ $t('global.action.add') }}
45 </b-button>
46 </template>
47 </b-modal>
48</template>
49
50<script>
51import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -070052import { useVuelidate } from '@vuelidate/core';
Surya Venkatesan4626aec2024-09-19 15:06:49 +053053import { helpers } from 'vuelidate/lib/validators';
54import { required } from '@vuelidate/validators';
Surya Vde23ea22024-07-11 15:19:46 +053055import { useI18n } from 'vue-i18n';
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060056
57const validateHostname = helpers.regex('validateHostname', /^\S{0,64}$/);
58
59export default {
60 mixins: [VuelidateMixin],
61 props: {
62 hostname: {
63 type: String,
64 default: '',
65 },
66 },
Hariharan Rangasamyc5d60f52025-10-31 12:58:56 +053067 emits: ['ok', 'hidden'],
Ed Tanous7d6b44c2024-03-23 14:56:34 -070068 setup() {
69 return {
70 v$: useVuelidate(),
71 };
72 },
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060073 data() {
74 return {
Surya Vde23ea22024-07-11 15:19:46 +053075 $t: useI18n().t,
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060076 form: {
77 hostname: '',
78 },
79 };
80 },
81 watch: {
82 hostname() {
83 this.form.hostname = this.hostname;
84 },
85 },
86 validations() {
87 return {
88 form: {
89 hostname: {
90 required,
91 validateHostname,
92 },
93 },
94 };
95 },
96 methods: {
97 handleSubmit() {
Surya Vde23ea22024-07-11 15:19:46 +053098 this.v$.$touch();
99 if (this.v$.$invalid) return;
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -0600100 this.$emit('ok', { HostName: this.form.hostname });
101 this.closeModal();
102 },
103 closeModal() {
104 this.$nextTick(() => {
105 this.$refs.modal.hide();
106 });
107 },
108 resetForm() {
109 this.form.hostname = this.hostname;
Surya Vde23ea22024-07-11 15:19:46 +0530110 this.v$.$reset();
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -0600111 this.$emit('hidden');
112 },
113 onOk(bvModalEvt) {
114 // prevent modal close
115 bvModalEvt.preventDefault();
116 this.handleSubmit();
117 },
118 },
119};
120</script>