Skip to content

Commit

Permalink
fix: distance can be zero and fix for commute deduction mandatory mes…
Browse files Browse the repository at this point in the history
…sage
  • Loading branch information
suyashpatil78 committed Mar 13, 2024
1 parent 26d9faf commit fa1d444
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/app/fyle/add-edit-mileage/add-edit-mileage.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
*ngIf="fg.controls.commuteDeduction.touched && !fg.controls.commuteDeduction.valid"
class="add-edit-mileage--error"
>
Select Commute Deduction.
Please select commute deduction.
</div>
</ng-container>
</ng-container>
Expand Down
7 changes: 5 additions & 2 deletions src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1028,11 +1028,12 @@ export class AddEditMileagePage implements OnInit {
txn_dt: this.fg.controls.dateOfSpend,
project_id: this.fg.controls.project,
billable: this.fg.controls.billable,
commute_deduction: this.fg.controls.commuteDeduction,
};

for (const [key, control] of Object.entries(keyToControlMap)) {
control.clearValidators();
if (key === 'project_id') {
if (key === 'project_id' || key === 'commute_deduction') {
control.updateValueAndValidity({
emitEvent: false,
});
Expand All @@ -1059,11 +1060,13 @@ export class AddEditMileagePage implements OnInit {
? null
: Validators.required
);
} else if (txnFieldKey === 'commute_deduction') {
control.setValidators(orgSettings.commute_deduction_settings.enabled ? Validators.required : null);
} else {
control.setValidators(isConnected ? Validators.required : null);
}
}
if (txnFieldKey === 'project_id') {
if (txnFieldKey === 'project_id' || txnFieldKey === 'commute_deduction') {
control.updateValueAndValidity({
emitEvent: false,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ export class RouteSelectorComponent implements OnInit, ControlValueAccessor, OnD
this.onChangeSub.unsubscribe();
}

customDistanceValidator(control: AbstractControl) {
customDistanceValidator(control: AbstractControl): { invalidDistance: boolean } {
const passedInDistance = control.value && +control.value;
if (passedInDistance !== null) {
return passedInDistance > 0
return passedInDistance >= 0
? null
: {
invalidDistance: true,
Expand Down

0 comments on commit fa1d444

Please sign in to comment.