Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 1 | <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" |
| 19 | :state="getValidationState($v.form.staticDns)" |
| 20 | @input="$v.form.staticDns.$touch()" |
| 21 | /> |
| 22 | <b-form-invalid-feedback role="alert"> |
| 23 | <template v-if="!$v.form.staticDns.required"> |
| 24 | {{ $t('global.form.fieldRequired') }} |
| 25 | </template> |
| 26 | <template v-if="!$v.form.staticDns.ipAddress"> |
| 27 | {{ $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> |
| 46 | import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js'; |
| 47 | import { ipAddress, required } from 'vuelidate/lib/validators'; |
| 48 | |
| 49 | export default { |
| 50 | mixins: [VuelidateMixin], |
| 51 | data() { |
| 52 | return { |
| 53 | form: { |
| 54 | staticDns: null, |
| 55 | }, |
| 56 | }; |
| 57 | }, |
| 58 | validations() { |
| 59 | return { |
| 60 | form: { |
| 61 | staticDns: { |
| 62 | required, |
| 63 | ipAddress, |
| 64 | }, |
| 65 | }, |
| 66 | }; |
| 67 | }, |
| 68 | methods: { |
| 69 | handleSubmit() { |
| 70 | this.$v.$touch(); |
| 71 | if (this.$v.$invalid) return; |
| 72 | this.$emit('ok', [this.form.staticDns]); |
| 73 | this.closeModal(); |
| 74 | }, |
| 75 | closeModal() { |
| 76 | this.$nextTick(() => { |
| 77 | this.$refs.modal.hide(); |
| 78 | }); |
| 79 | }, |
| 80 | resetForm() { |
| 81 | this.form.staticDns = null; |
| 82 | this.$v.$reset(); |
| 83 | this.$emit('hidden'); |
| 84 | }, |
| 85 | onOk(bvModalEvt) { |
| 86 | // prevent modal close |
| 87 | bvModalEvt.preventDefault(); |
| 88 | this.handleSubmit(); |
| 89 | }, |
| 90 | }, |
| 91 | }; |
| 92 | </script> |