TT#40253 Notify user invalid destination input

What has been done:
- TT#43257, Bind validation functions to the input fields
- TT#43256, Provide proper error messages and put these in the
  translation file

Change-Id: I3b8d9c7b627fab960fc5491b0bb8aa9266f6bc73
changes/44/23144/5
raxelsen 7 years ago committed by Hans-Peter Herzog
parent 91e33e2516
commit f6795c77b0

@ -71,10 +71,10 @@
], ],
computed: { computed: {
errorMessage() { errorMessage() {
return this.$t('call.inputValidNumber'); return this.$t('validationErrors.inputValidNumber');
}, },
helperMessage() { helperMessage() {
return this.$t('call.inputNumber'); return this.$t('validationErrors.inputNumber');
}, },
inputReadonly() { inputReadonly() {
return this.isMobile; return this.isMobile;

@ -29,8 +29,7 @@
</q-btn> </q-btn>
<div v-if="isFormEnabled"> <div v-if="isFormEnabled">
<q-field <q-field
:error="addFormError" :error-label="destinationInputError"
:error-label="$t('pages.callForward.addInputError')"
> >
<q-input <q-input
:before="beforeIconDestination" :before="beforeIconDestination"
@ -41,11 +40,13 @@
:clearable="isFormTypeNumber" :clearable="isFormTypeNumber"
:autofocus="isFormTypeNumber" :autofocus="isFormTypeNumber"
:disable="!isFormTypeNumber || addDestinationIsRequesting" :disable="!isFormTypeNumber || addDestinationIsRequesting"
@input="$v.destinationForm.destination.$touch"
@blur="$v.destinationForm.destination.$touch"
:error="$v.destinationForm.destination.$error"
/> />
</q-field> </q-field>
<q-field <q-field
:error="addFormError" :error-label="timeoutInputError"
:error-label="$t('pages.callForward.addInputError')"
> >
<q-input <q-input
v-if="isFormTypeNumber" v-if="isFormTypeNumber"
@ -54,6 +55,9 @@
type="number" type="number"
v-model="destinationForm.timeout" v-model="destinationForm.timeout"
suffix="seconds" suffix="seconds"
@input="$v.destinationForm.timeout.$touch"
@blur="$v.destinationForm.timeout.$touch"
:error="$v.destinationForm.timeout.$error"
/> />
</q-field> </q-field>
<q-btn <q-btn
@ -68,6 +72,7 @@
color="primary" color="primary"
icon-right="fa-save" icon-right="fa-save"
@click="addDestination()" @click="addDestination()"
:disable="$v.destinationForm.destination.$error || $v.destinationForm.timeout.$error"
> >
{{ $t('buttons.save') }} {{ $t('buttons.save') }}
</q-btn> </q-btn>
@ -76,12 +81,31 @@
</template> </template>
<script> <script>
import _ from 'lodash' import _ from 'lodash'
import { startLoading } from '../../../helpers/ui' import {
import { mapGetters, mapState } from 'vuex' startLoading,
import { QItem, Toast, QBtn, QSelect, QPopover, QList, showGlobalError
QField, QInput, QSlider } from 'quasar-framework' } from '../../../helpers/ui'
import {
mapGetters,
mapState
} from 'vuex'
import {
required,
maxLength,
minValue
} from 'vuelidate/lib/validators'
import {
QItem,
Toast,
QBtn,
QSelect,
QPopover,
QList,
QField,
QInput,
QSlider
} from 'quasar-framework'
export default { export default {
name: 'csc-add-destination-form', name: 'csc-add-destination-form',
props: [ props: [
@ -95,7 +119,6 @@
], ],
data () { data () {
return { return {
addFormError: false,
formEnabled: false, formEnabled: false,
destinationForm: { destinationForm: {
destination: '', destination: '',
@ -114,6 +137,18 @@
Toast, Toast,
QBtn QBtn
}, },
validations: {
destinationForm: {
destination: {
required,
maxLength: maxLength(64)
},
timeout: {
required,
minValue: minValue(1)
}
}
},
computed: { computed: {
...mapState('callForward', [ ...mapState('callForward', [
'activeForm', 'activeForm',
@ -124,6 +159,32 @@
'hasSendFaxFeature', 'hasSendFaxFeature',
'hasFaxCapability' 'hasFaxCapability'
]), ]),
destinationInputError() {
if (!this.$v.destinationForm.destination.maxLength) {
return this.$t('validationErrors.maxLength', {
field: this.$t('pages.callForward.destination'),
maxLength: this.$v.destinationForm.destination.$params.maxLength.max
});
}
else if (!this.$v.destinationForm.destination.required) {
return this.$t('validationErrors.fieldRequired', {
field: this.$t('pages.callForward.destination')
});
}
},
timeoutInputError() {
if (!this.$v.destinationForm.timeout.minValue) {
return this.$t('validationErrors.minValueSecond', {
field: this.$t('pages.callForward.timeout'),
minValue: this.$v.destinationForm.timeout.$params.minValue.min
});
}
else if (!this.$v.destinationForm.timeout.required) {
return this.$t('validationErrors.fieldRequired', {
field: this.$t('pages.callForward.timeout')
});
}
},
isFormTypeNumber() { isFormTypeNumber() {
return this.formType === 'number'; return this.formType === 'number';
}, },
@ -178,14 +239,20 @@
this.$store.commit('callForward/resetDestinationState'); this.$store.commit('callForward/resetDestinationState');
}, },
addDestination() { addDestination() {
startLoading(); if (this.$v.destinationForm.destination.$error ||
this.$store.dispatch('callForward/addDestination', { this.$v.destinationForm.timeout.$error) {
form: this.destinationForm, showGlobalError(this.$t('validationErrors.generic'));
destinations: this.destinations, }
timeset: this.timeset, else {
timesetId: this.timesetId, startLoading();
sourcesetId: this.sourcesetId this.$store.dispatch('callForward/addDestination', {
}); form: this.destinationForm,
destinations: this.destinations,
timeset: this.timeset,
timesetId: this.timesetId,
sourcesetId: this.sourcesetId
});
}
} }
} }
} }

@ -3,6 +3,7 @@
<q-field :error-label="groupNameErrorMessage"> <q-field :error-label="groupNameErrorMessage">
<q-input <q-input
@input="$v.data.name.$touch" @input="$v.data.name.$touch"
@blur="$v.data.name.$touch"
:error="$v.data.name.$error" :error="$v.data.name.$error"
:disabled="loading" :disabled="loading"
:readonly="loading" :readonly="loading"
@ -15,6 +16,7 @@
<q-field :error-label="extensionErrorMessage"> <q-field :error-label="extensionErrorMessage">
<q-input <q-input
@input="$v.data.extension.$touch" @input="$v.data.extension.$touch"
@blur="$v.data.extension.$touch"
:error="$v.data.extension.$error" :error="$v.data.extension.$error"
:disabled="loading" :disabled="loading"
:readonly="loading" :readonly="loading"
@ -100,7 +102,6 @@
</template> </template>
<script> <script>
import { import {
required, required,
minValue, minValue,
@ -171,38 +172,50 @@
computed: { computed: {
groupNameErrorMessage() { groupNameErrorMessage() {
if (!this.$v.data.name.required) { if (!this.$v.data.name.required) {
return this.$t('pbxConfig.requiredGroupName'); return this.$t('validationErrors.fieldRequired', {
field: this.$t('pbxConfig.groupName')
});
} }
else if (!this.$v.data.name.maxLength) { else if (!this.$v.data.name.maxLength) {
return this.$t('pbxConfig.groupNameMaxLength', { return this.$t('validationErrors.maxLength', {
field: this.$t('pbxConfig.groupName'),
maxLength: this.$v.data.name.$params.maxLength.max maxLength: this.$v.data.name.$params.maxLength.max
}); });
} }
}, },
extensionErrorMessage() { extensionErrorMessage() {
if (!this.$v.data.extension.required) { if (!this.$v.data.extension.required) {
return this.$t('pbxConfig.requiredExtension'); return this.$t('validationErrors.fieldRequired', {
field: this.$t('pbxConfig.extension')
});
} }
else if (!this.$v.data.name.maxLength) { else if (!this.$v.data.extension.maxLength) {
return this.$t('pbxConfig.extensionMaxLength', { return this.$t('validationErrors.maxLength', {
field: this.$t('pbxConfig.extension'),
maxLength: this.$v.data.extension.$params.maxLength.max maxLength: this.$v.data.extension.$params.maxLength.max
}); });
} }
else if (!this.$v.data.name.numeric) { else if (!this.$v.data.extension.numeric) {
return this.$t('pbxConfig.extensionAlphaNum'); return this.$t('validationErrors.alphaNum', {
field: this.$t('pbxConfig.extension'),
});
} }
}, },
huntTimeoutErrorMessage() { huntTimeoutErrorMessage() {
if (!this.$v.data.huntTimeout.required) { if (!this.$v.data.huntTimeout.required) {
return this.$t('pbxConfig.requiredHuntTimeout'); return this.$t('validationErrors.fieldRequired', {
field: this.$t('pbxConfig.huntTimeoutSentence')
});
} }
else if (!this.$v.data.huntTimeout.minValue) { else if (!this.$v.data.huntTimeout.minValue) {
return this.$t('pbxConfig.huntTimeoutMinValue', { return this.$t('validationErrors.minValueSecond', {
field: this.$t('pbxConfig.huntTimeoutSentence'),
minValue: this.$v.data.huntTimeout.$params.minValue.min minValue: this.$v.data.huntTimeout.$params.minValue.min
}); });
} }
else if (!this.$v.data.huntTimeout.maxValue) { else if (!this.$v.data.huntTimeout.maxValue) {
return this.$t('pbxConfig.huntTimeoutMaxValue', { return this.$t('validationErrors.maxValueSecond', {
field: this.$t('pbxConfig.huntTimeoutSentence'),
maxValue: this.$v.data.huntTimeout.$params.maxValue.max maxValue: this.$v.data.huntTimeout.$params.maxValue.max
}); });
} }

@ -58,7 +58,7 @@
class="csc-list-item-main" class="csc-list-item-main"
v-if="expanded" v-if="expanded"
> >
<q-field :label="$t('pbxConfig.seatName')"> <q-field :label="$t('pbxConfig.name')">
<q-input <q-input
v-model="changes.name" v-model="changes.name"
:after="nameButtons" :after="nameButtons"

@ -3,18 +3,20 @@
<q-field :error-label="seatNameErrorMessage"> <q-field :error-label="seatNameErrorMessage">
<q-input <q-input
@input="$v.data.name.$touch" @input="$v.data.name.$touch"
@blur="$v.data.name.$touch"
:error="$v.data.name.$error" :error="$v.data.name.$error"
:disabled="loading" :disabled="loading"
:readonly="loading" :readonly="loading"
v-model="data.name" v-model="data.name"
autofocus autofocus
:float-label="$t('pbxConfig.seatName')" :float-label="$t('pbxConfig.name')"
clearable clearable
/> />
</q-field> </q-field>
<q-field :error-label="extensionErrorMessage"> <q-field :error-label="extensionErrorMessage">
<q-input <q-input
@input="$v.data.extension.$touch" @input="$v.data.extension.$touch"
@blur="$v.data.extension.$touch"
:error="$v.data.extension.$error" :error="$v.data.extension.$error"
:disabled="loading" :disabled="loading"
:readonly="loading" :readonly="loading"
@ -138,25 +140,33 @@
computed: { computed: {
seatNameErrorMessage() { seatNameErrorMessage() {
if (!this.$v.data.name.required) { if (!this.$v.data.name.required) {
return this.$t('pbxConfig.requiredSeatName'); return this.$t('validationErrors.fieldRequired', {
field: this.$t('pbxConfig.seatName')
});
} }
else if (!this.$v.data.name.maxLength) { else if (!this.$v.data.name.maxLength) {
return this.$t('pbxConfig.seatNameMaxLength', { return this.$t('validationErrors.maxLength', {
field: this.$t('pbxConfig.seatName'),
maxLength: this.$v.data.name.$params.maxLength.max maxLength: this.$v.data.name.$params.maxLength.max
}); });
} }
}, },
extensionErrorMessage() { extensionErrorMessage() {
if (!this.$v.data.extension.required) { if (!this.$v.data.extension.required) {
return this.$t('pbxConfig.requiredExtension'); return this.$t('validationErrors.fieldRequired', {
field: this.$t('pbxConfig.extension')
});
} }
else if (!this.$v.data.name.maxLength) { else if (!this.$v.data.extension.maxLength) {
return this.$t('pbxConfig.extensionMaxLength', { return this.$t('validationErrors.maxLength', {
field: this.$t('pbxConfig.extension'),
maxLength: this.$v.data.extension.$params.maxLength.max maxLength: this.$v.data.extension.$params.maxLength.max
}); });
} }
else if (!this.$v.data.name.numeric) { else if (!this.$v.data.extension.numeric) {
return this.$t('pbxConfig.extensionAlphaNum'); return this.$t('validationErrors.alphaNum', {
field: this.$t('pbxConfig.extension'),
});
} }
} }
}, },

@ -24,8 +24,15 @@
"callNotAvailable": "Could not initialize call functionality properly" "callNotAvailable": "Could not initialize call functionality properly"
}, },
"validationErrors": { "validationErrors": {
"generic": "You have invalid form input. Please check and try again.",
"required": "This field is required.",
"maxLength": "{field} must have at most {maxLength} letters",
"fieldRequired": "{field} is required", "fieldRequired": "{field} is required",
"minValueSecond": "{field} must be at least {minValue} second" "minValueSecond": "{field} must be at least {minValue} second",
"maxValueSecond": "{field} must be maximum of {maxValue} seconds",
"alphaNum": "{field} must consist of numeric characters only",
"inputNumber": "Input a phone number",
"inputValidNumber": "Input a valid phone number"
}, },
"navigation": { "navigation": {
"home": { "home": {
@ -277,8 +284,6 @@
"incoming": "Incoming ...", "incoming": "Incoming ...",
"ended": "Ended", "ended": "Ended",
"call": "Established", "call": "Established",
"inputNumber": "Input a phone number",
"inputValidNumber": "Input a valid phone number",
"number": "Phone number", "number": "Phone number",
"endCall": "End Call", "endCall": "End Call",
"endCallDialog": "You are about to end the current call. Are you sure?", "endCallDialog": "You are about to end the current call. Are you sure?",
@ -297,6 +302,7 @@
"groupName": "Group Name", "groupName": "Group Name",
"huntPolicy": "Hunt Policy", "huntPolicy": "Hunt Policy",
"huntTimeout": "Hunt Timeout", "huntTimeout": "Hunt Timeout",
"huntTimeoutSentence": "Hunt timeout",
"primaryNumber": "Primary Number", "primaryNumber": "Primary Number",
"aliasNumbers": "Alias Numbers", "aliasNumbers": "Alias Numbers",
"serialRinging": "Serial Ringing", "serialRinging": "Serial Ringing",
@ -309,7 +315,9 @@
"removeGroup": "Remove group", "removeGroup": "Remove group",
"removeGroupTitle": "Remove group", "removeGroupTitle": "Remove group",
"removeGroupText": "You are about to remove group {group}", "removeGroupText": "You are about to remove group {group}",
"seatName": "Name", "groupName": "Group name",
"name": "Name",
"seatName": "Seat name",
"addSeat": "Add Seat", "addSeat": "Add Seat",
"removeSeat": "Remove seat", "removeSeat": "Remove seat",
"removeSeatTitle": "Remove seat", "removeSeatTitle": "Remove seat",
@ -327,18 +335,6 @@
"noStationName": "Could not find any device with station name matching the filter criteria", "noStationName": "Could not find any device with station name matching the filter criteria",
"noGroups": "No groups created yet", "noGroups": "No groups created yet",
"noSeats": "No seats created yet", "noSeats": "No seats created yet",
"requiredGroupName": "Group name is required",
"groupNameMaxLength": "Group name must have at most {maxLength} letters",
"requiredExtension": "Extension is required",
"extensionMinValue": "Extension must be at least {minValue}",
"extensionMaxValue": "Extension must be maximum {maxValue}",
"requiredHuntTimeout": "Hunt timeout is required",
"huntTimeoutMinValue": "Hunt timeout must be at least {minValue} second",
"huntTimeoutMaxValue": "Hunt timeout must be maximum {maxValue} seconds",
"requiredSeatName": "Seat name is required",
"seatNameMaxLength": "Seat name must have at most {maxLength} letters",
"extensionMaxLength": "Extension must have at most {maxLength} letters",
"extensionAlphaNum": "Only numeric characters are allowed",
"toasts": { "toasts": {
"changedFieldToast": "Changed {type} to {name}", "changedFieldToast": "Changed {type} to {name}",
"updatedAliasNumbersToast": "Alias numbers field updated!", "updatedAliasNumbersToast": "Alias numbers field updated!",

Loading…
Cancel
Save