Vuelidate, I18n, and filter are upgraded to vue3
While navigating to the pages i18n, vuelidate, and filters errors
occurred. i18n, and vuelidate code changes in each page adapted to
vue3. Filter global function for date and time format implemented
in the main.js file and those files which as called the filter
functions.
Change-Id: If1a2ee22d47750faef1c35ef2c263299067d9a20
Signed-off-by: Surya Venkatesan <suryav@ami.com>
diff --git a/src/views/Settings/DateTime/DateTime.vue b/src/views/Settings/DateTime/DateTime.vue
index 00d7b45..b86ebd2 100644
--- a/src/views/Settings/DateTime/DateTime.vue
+++ b/src/views/Settings/DateTime/DateTime.vue
@@ -18,14 +18,14 @@
<b-col lg="3">
<dl>
<dt>{{ $t('pageDateTime.form.date') }}</dt>
- <dd v-if="bmcTime">{{ bmcTime }}</dd>
+ <dd v-if="bmcTime">{{ $filters.formatDate(bmcTime) }}</dd>
<dd v-else>--</dd>
</dl>
</b-col>
<b-col lg="3">
<dl>
<dt>{{ $t('pageDateTime.form.time.label') }}</dt>
- <dd v-if="bmcTime">{{ bmcTime }}</dd>
+ <dd v-if="bmcTime">{{ $filters.formatTime(bmcTime) }}</dd>
<dd v-else>--</dd>
</dl>
</b-col>
@@ -56,17 +56,17 @@
<b-form-input
id="input-manual-date"
v-model="form.manual.date"
- :state="getValidationState($v.form.manual.date)"
+ :state="getValidationState(v$.form.manual.date)"
:disabled="ntpOptionSelected"
data-test-id="dateTime-input-manualDate"
class="form-control-with-button"
- @blur="$v.form.manual.date.$touch()"
+ @blur="v$.form.manual.date.$touch()"
/>
<b-form-invalid-feedback role="alert">
- <div v-if="!$v.form.manual.date.pattern">
+ <div v-if="!v$.form.manual.date.pattern">
{{ $t('global.form.invalidFormat') }}
</div>
- <div v-if="!$v.form.manual.date.required">
+ <div v-if="!v$.form.manual.date.required">
{{ $t('global.form.fieldRequired') }}
</div>
</b-form-invalid-feedback>
@@ -105,16 +105,16 @@
<b-form-input
id="input-manual-time"
v-model="form.manual.time"
- :state="getValidationState($v.form.manual.time)"
+ :state="getValidationState(v$.form.manual.time)"
:disabled="ntpOptionSelected"
data-test-id="dateTime-input-manualTime"
- @blur="$v.form.manual.time.$touch()"
+ @blur="v$.form.manual.time.$touch()"
/>
<b-form-invalid-feedback role="alert">
- <div v-if="!$v.form.manual.time.pattern">
+ <div v-if="!v$.form.manual.time.pattern">
{{ $t('global.form.invalidFormat') }}
</div>
- <div v-if="!$v.form.manual.time.required">
+ <div v-if="!v$.form.manual.time.required">
{{ $t('global.form.fieldRequired') }}
</div>
</b-form-invalid-feedback>
@@ -139,13 +139,13 @@
<b-form-input
id="input-ntp-1"
v-model="form.ntp.firstAddress"
- :state="getValidationState($v.form.ntp.firstAddress)"
+ :state="getValidationState(v$.form.ntp.firstAddress)"
:disabled="manualOptionSelected"
data-test-id="dateTime-input-ntpServer1"
- @blur="$v.form.ntp.firstAddress.$touch()"
+ @blur="v$.form.ntp.firstAddress.$touch()"
/>
<b-form-invalid-feedback role="alert">
- <div v-if="!$v.form.ntp.firstAddress.required">
+ <div v-if="!v$.form.ntp.firstAddress.required">
{{ $t('global.form.fieldRequired') }}
</div>
</b-form-invalid-feedback>
@@ -210,6 +210,7 @@
import { mapState } from 'vuex';
import { requiredIf, helpers } from '@vuelidate/validators';
+import { useI18n } from 'vue-i18n';
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]$/;
@@ -234,6 +235,7 @@
},
data() {
return {
+ $t: useI18n().t,
locale: this.$store.getters['global/languagePreference'],
form: {
configurationSelected: 'manual',
@@ -302,10 +304,10 @@
this.emitChange();
},
bmcTime() {
- this.form.manual.date = this.$options.filters.formatDate(
+ this.form.manual.date = this.$filters.formatDate(
this.$store.getters['global/bmcTime'],
);
- this.form.manual.time = this.$options.filters
+ this.form.manual.time = this.$filters
.formatTime(this.$store.getters['global/bmcTime'])
.slice(0, 5);
},
@@ -320,8 +322,8 @@
},
methods: {
emitChange() {
- if (this.$v.$invalid) return;
- this.$v.$reset(); //reset to re-validate on blur
+ if (this.v$.$invalid) return;
+ this.v$.$reset(); //reset to re-validate on blur
this.$emit('change', {
manualDate: this.manualDate ? new Date(this.manualDate) : null,
});
@@ -337,8 +339,8 @@
] = [this.ntpServers[0], this.ntpServers[1], this.ntpServers[2]];
},
submitForm() {
- this.$v.$touch();
- if (this.$v.$invalid) return;
+ this.v$.$touch();
+ if (this.v$.$invalid) return;
this.startLoader();
let dateTimeForm = {};
@@ -398,7 +400,7 @@
})
.catch(({ message }) => this.errorToast(message))
.finally(() => {
- this.$v.form.$reset();
+ this.v$.form.$reset();
this.endLoader();
});
},