From a0cb2a78e019662e57c73e77e8c4ba587bd0f14e Mon Sep 17 00:00:00 2001
From: Vitalii Lysak <v.lysak@dunice.net>
Date: Fri, 5 Aug 2022 14:38:39 +0300
Subject: SILABMC-223: ntp validation

---
 src/views/_sila/Overview/DateTime/DateTime.vue | 32 +++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

(limited to 'src/views/_sila/Overview/DateTime/DateTime.vue')

diff --git a/src/views/_sila/Overview/DateTime/DateTime.vue b/src/views/_sila/Overview/DateTime/DateTime.vue
index 66871699..796a57ac 100644
--- a/src/views/_sila/Overview/DateTime/DateTime.vue
+++ b/src/views/_sila/Overview/DateTime/DateTime.vue
@@ -145,6 +145,9 @@
                     @blur="$v.form.ntp.firstAddress.$touch()"
                   />
                   <b-form-invalid-feedback role="alert">
+                    <div v-if="!$v.form.ntp.firstAddress.pattern">
+                      {{ $t('global.form.invalidFormat') }}
+                    </div>
                     <div v-if="!$v.form.ntp.firstAddress.required">
                       {{ $t('global.form.fieldRequired') }}
                     </div>
@@ -161,9 +164,16 @@
                   <b-form-input
                     id="input-ntp-2"
                     v-model="form.ntp.secondAddress"
+                    :state="getValidationState($v.form.ntp.secondAddress)"
                     :disabled="manualOptionSelected"
                     data-test-id="dateTime-input-ntpServer2"
+                    @blur="$v.form.ntp.secondAddress.$touch()"
                   />
+                  <b-form-invalid-feedback role="alert">
+                    <div v-if="!$v.form.ntp.secondAddress.pattern">
+                      {{ $t('global.form.invalidFormat') }}
+                    </div>
+                  </b-form-invalid-feedback>
                 </b-input-group>
               </b-form-group>
             </b-col>
@@ -176,9 +186,16 @@
                   <b-form-input
                     id="input-ntp-3"
                     v-model="form.ntp.thirdAddress"
+                    :state="getValidationState($v.form.ntp.thirdAddress)"
                     :disabled="manualOptionSelected"
                     data-test-id="dateTime-input-ntpServer3"
+                    @blur="$v.form.ntp.thirdAddress.$touch()"
                   />
+                  <b-form-invalid-feedback role="alert">
+                    <div v-if="!$v.form.ntp.thirdAddress.pattern">
+                      {{ $t('global.form.invalidFormat') }}
+                    </div>
+                  </b-form-invalid-feedback>
                 </b-input-group>
               </b-form-group>
             </b-col>
@@ -208,13 +225,15 @@ import LoadingBarMixin, {
 } from '@/components/_sila/Mixins/LoadingBarMixin';
 import LocalTimezoneLabelMixin from '@/components/_sila/Mixins/LocalTimezoneLabelMixin';
 import VuelidateMixin from '@/components/_sila/Mixins/VuelidateMixin.js';
+import {
+  isoDateRegex,
+  isoTimeRegex,
+  isoNtpRegex,
+} from '@/utilities/_sila/regexConstants';
 
 import { mapState } from 'vuex';
 import { requiredIf, helpers } from 'vuelidate/lib/validators';
 
-const isoDateRegex = /([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/;
-const isoTimeRegex = /^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/;
-
 export default {
   name: 'DateTime',
   components: { Alert, IconCalendar, PageTitle, PageSection },
@@ -264,6 +283,13 @@ export default {
             required: requiredIf(function () {
               return this.form.configurationSelected === 'ntp';
             }),
+            pattern: helpers.regex('pattern', isoNtpRegex),
+          },
+          secondAddress: {
+            pattern: helpers.regex('pattern', isoNtpRegex),
+          },
+          thirdAddress: {
+            pattern: helpers.regex('pattern', isoNtpRegex),
           },
         },
       },
-- 
cgit v1.2.3

