Skip to content

Commit

Permalink
Merge pull request #347 from bcgov/ofmcc-5789-transport-validation-en…
Browse files Browse the repository at this point in the history
…hancement

Ofmcc 5789 transport validation enhancement
  • Loading branch information
jenbeckett authored Aug 30, 2024
2 parents c1455fb + 963407d commit cd7249a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
26 changes: 12 additions & 14 deletions frontend/src/components/supp-allowances/TransportationAllowance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,12 @@
<p>Vehicle mileage at time of application (odometer reading):</p>
</v-col>
<v-col cols="6" xl="7" class="pt-2 text-center">
<v-text-field
<AppNumberInput
v-model="model.odometer"
required
type="number"
:format="wholeNumberFormat"
suffix="km"
variant="outlined"
density="compact"
:rules="[rules.max(999999), ...rules.required]"
:disabled="readOnly(model)"></v-text-field>
:rules="[rules.max(999999), rules.min(1), ...rules.required]"
:disabled="readOnly(model)"></AppNumberInput>
</v-col>
</v-row>
</v-col>
Expand All @@ -98,15 +95,12 @@
<p>Estimated Yearly KM:</p>
</v-col>
<v-col cols="6" xl="7" class="pt-2 text-center">
<v-text-field
<AppNumberInput
v-model="model.estimatedMileage"
required
type="number"
:format="wholeNumberFormat"
suffix="km"
variant="outlined"
density="compact"
:rules="[rules.max(999999), ...rules.required]"
:disabled="readOnly(model)"></v-text-field>
:rules="[rules.max(999999), rules.min(1), ...rules.required]"
:disabled="readOnly(model)"></AppNumberInput>
</v-col>
</v-row>
</v-col>
Expand Down Expand Up @@ -227,6 +221,10 @@ export default {
separator: ',',
precision: 2,
},
wholeNumberFormat: {
nullValue: '',
precision: 0,
},
}
},
computed: {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const rules = {
return (v) => !v || v <= number || `Max exceeded: ${number.toLocaleString('en-ca')}`
},
min(number) {
return (v) => !v || v >= number || `Min exceeded: ${number.toLocaleString('en-ca')}`
return (v) => !v || v >= number || `Please enter a number greater than ${(number - 1).toLocaleString('en-ca')} in the field`
},
maxLength(number) {
return (v) => !v || v.length <= number || 'Max length exceeded'
Expand Down
15 changes: 14 additions & 1 deletion frontend/src/views/supp-allowances/SupplementaryFormView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ export default {
//disable all components on the form if user is in bad standing or does not have correct permissions
return !this.hasGoodStanding || !this.hasPermission(this.PERMISSIONS.APPLY_FOR_FUNDING)
},
transportAppsHaveZero() {
return this.models
.filter((el) => el.supplementaryType === SUPPLEMENTARY_TYPES.TRANSPORT)
?.some((el) => el?.odometer === 0 || el?.odometer === '0' || el?.estimatedMileage === 0 || el?.estimatedMileage === '0')
},
},
watch: {
back: {
Expand All @@ -243,7 +248,10 @@ export default {
},
next: {
async handler() {
if (this.hasPermission(this.PERMISSIONS.APPLY_FOR_FUNDING)) {
if (this.transportAppsHaveZero) {
await this.$refs.form?.validate()
return
} else if (this.hasPermission(this.PERMISSIONS.APPLY_FOR_FUNDING)) {
await this.saveApplication()
}
const applicationId = this.applicationId ? this.applicationId : this.$route.params.applicationGuid
Expand Down Expand Up @@ -296,6 +304,11 @@ export default {
}
},
async saveApplication(showAlert = false) {
if (this.transportAppsHaveZero) {
await this.$refs.form?.validate()
this.setFailureAlert('Failed to save Transportation Allowance')
return
}
try {
this.loading = true
this.$emit('process', true)
Expand Down

0 comments on commit cd7249a

Please sign in to comment.