TT#40252 Validation for PBXDevice add form

Change-Id: Ie43af84b92529e81a50620af917805b6a66e231e
changes/96/23396/4
raxelsen 8 years ago
parent 3ee331328d
commit cd40d0bf6f

@ -1,7 +1,10 @@
<template> <template>
<div> <div>
<q-field> <q-field :error-label="stationNameErrorMessage">
<q-input <q-input
@input="$v.data.station_name.$touch"
@blur="$v.data.station_name.$touch"
:error="$v.data.station_name.$error"
v-model="data.station_name" v-model="data.station_name"
:disabled="loading" :disabled="loading"
:readonly="loading" :readonly="loading"
@ -10,8 +13,11 @@
clearable clearable
/> />
</q-field> </q-field>
<q-field> <q-field :error-label="identifierErrorMessage">
<q-input <q-input
@input="$v.data.identifier.$touch"
@blur="$v.data.identifier.$touch"
:error="$v.data.identifier.$error"
v-model="data.identifier" v-model="data.identifier"
:disabled="loading" :disabled="loading"
:readonly="loading" :readonly="loading"
@ -26,6 +32,7 @@
:label="$t('pbxConfig.deviceModel')" :label="$t('pbxConfig.deviceModel')"
@opened="modelSelectOpened()" @opened="modelSelectOpened()"
@select="selectProfile" @select="selectProfile"
@reseted="resetProfile"
/> />
</q-field> </q-field>
<div <div
@ -36,14 +43,19 @@
flat color="secondary" flat color="secondary"
icon="clear" icon="clear"
@click="cancel()" @click="cancel()"
>{{ $t('buttons.cancel') }}</q-btn> >
{{ $t('buttons.cancel') }}
</q-btn>
<q-btn <q-btn
v-if="!loading" v-if="!loading"
flat flat
color="primary" color="primary"
icon="done" icon="done"
@click="save()" @click="save()"
>{{ $t('buttons.save') }}</q-btn> :disabled="$v.data.$invalid || !data.profile_id"
>
{{ $t('buttons.save') }}
</q-btn>
</div> </div>
<q-inner-loading <q-inner-loading
v-show="loading" v-show="loading"
@ -58,7 +70,10 @@
</template> </template>
<script> <script>
import {
required,
maxLength
} from 'vuelidate/lib/validators'
import { import {
QCard, QCard,
QCardTitle, QCardTitle,
@ -100,12 +115,52 @@
QItem, QItem,
QItemMain QItemMain
}, },
validations: {
data: {
station_name: {
required,
maxLength: maxLength(64)
},
identifier: {
required,
maxLength: maxLength(64)
}
}
},
data () { data () {
return { return {
formEnabled: false, formEnabled: false,
data: this.getDefaults() data: this.getDefaults()
} }
}, },
computed: {
stationNameErrorMessage() {
if (!this.$v.data.station_name.required) {
return this.$t('validationErrors.fieldRequired', {
field: this.$t('pbxConfig.deviceStationName')
});
}
else if (!this.$v.data.station_name.maxLength) {
return this.$t('validationErrors.maxLength', {
field: this.$t('pbxConfig.deviceStationName'),
maxLength: this.$v.data.station_name.$params.maxLength.max
});
}
},
identifierErrorMessage() {
if (!this.$v.data.identifier.required) {
return this.$t('validationErrors.fieldRequired', {
field: this.$t('pbxConfig.deviceIdentifier')
});
}
else if (!this.$v.data.identifier.maxLength) {
return this.$t('validationErrors.maxLength', {
field: this.$t('pbxConfig.deviceIdentifier'),
maxLength: this.$v.data.identifier.$params.maxLength.max
});
}
}
},
methods: { methods: {
getDefaults() { getDefaults() {
return { return {
@ -136,6 +191,9 @@
}, },
selectProfile(profile) { selectProfile(profile) {
this.data.profile_id = profile.id; this.data.profile_id = profile.id;
},
resetProfile() {
this.data.profile_id = null;
} }
} }
} }

@ -123,7 +123,7 @@
let buttons = []; let buttons = [];
if (this.selectedProfile.device_id !== null && this.erasable === true) { if (this.selectedProfile.device_id !== null && this.erasable === true) {
buttons = [{ buttons = [{
icon: 'clear', icon: 'cancel',
error: false, error: false,
handler (event) { handler (event) {
event.stopPropagation(); event.stopPropagation();

@ -77,7 +77,6 @@
</template> </template>
<script> <script>
import { import {
required, required,
maxLength, maxLength,

Loading…
Cancel
Save