Skip to content

fix(routes-compute-routes): resolve API validation errors on optional dropdowns - #1669

Open
willum070 wants to merge 1 commit into
mainfrom
fix-routes-compute-routes
Open

fix(routes-compute-routes): resolve API validation errors on optional dropdowns#1669
willum070 wants to merge 1 commit into
mainfrom
fix-routes-compute-routes

Conversation

@willum070

@willum070 willum070 commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

What this PR does

Fixes an InvalidValueError thrown by the Routes API in the routes-compute-routes sample when submitting the form without selecting optional preferences.

Root Cause

In a previous chore update (#1574), new ESLint rules (@typescript-eslint/prefer-nullish-coalescing) prompted a switch from logical OR (||) to nullish coalescing (??) for handling optional <select> inputs.

Because FormData.get() returns an empty string ("") for default unselected options, the nullish coalescing operator ("" ?? undefined) evaluated to "" instead of undefined. This sent an invalid empty string value to the Maps API for enum fields, causing the validation error.

The Fix

Replaced the ?? fallback logic with explicit ternary operators (value === '' ? undefined : value) for the following optional fields:

  • routingPreference
  • polylineQuality
  • transitPreference.routingPreference

This ensures that empty strings correctly fall back to undefined before being sent to the API, while still satisfying the strict ESLint rules that prohibit the legacy || pattern.

Change-Id: Ifa79159c75cd2da592071c0d7cb4b20975fb5a8e

Change-Id: Ifa79159c75cd2da592071c0d7cb4b20975fb5a8e
@willum070
willum070 requested a review from kzubair14 September 10, 2026 21:09
@willum070 willum070 changed the title fix(routes-compute-routes): resolve API validation errors on optional dropdowns` fix(routes-compute-routes): resolve API validation errors on optional dropdowns Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant