Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: t.trim is not a function #382

Closed
gjvoosten opened this issue Oct 11, 2023 · 1 comment · Fixed by #383
Closed

Uncaught TypeError: t.trim is not a function #382

gjvoosten opened this issue Oct 11, 2023 · 1 comment · Fixed by #383

Comments

@gjvoosten
Copy link
Contributor

After upgrading to the latest version 3.10.0, I am getting the following error:
Screenshot from 2023-10-11 13-25-57

The reason for the exception appears to be that validateCoords(query) is called with an undefined query, so this change would fix it:

diff --git a/src/coords.ts b/src/coords.ts
index b874b8e..e413608 100644
--- a/src/coords.ts
+++ b/src/coords.ts
@@ -1,7 +1,7 @@
 // @ts-nocheck
 
 export function validateCoords(query) {
-  const q = query.trim();
+  const q = query?.trim();
   const regex = /^(-?[0-9]*\.?\s*[0-9]*)\s*,?\s*(-?[0-9]*\.?[0-9]*)$/g;
   const match = regex.exec(q);
   if (match) {
gjvoosten pushed a commit to gjvoosten/leaflet-geosearch that referenced this issue Oct 11, 2023
@gjvoosten gjvoosten changed the title Uncaught TypeError: regex.match is not a function Uncaught TypeError: t.trim is not a function Oct 11, 2023
gjvoosten added a commit to gjvoosten/leaflet-geosearch that referenced this issue Oct 11, 2023
@gjvoosten
Copy link
Contributor Author

gjvoosten commented Oct 18, 2023

Actually this issue isn't completely solved in v3.10.1; there is a difference between how validateCoords() is called while typing and after pressing Enter. While typing, it is called with the string that was typed in, and after pressing Enter, it is called with an object { query: this.searchElement.input.value, data: item } (see https://github.com/smeijer/leaflet-geosearch/blob/develop/src/SearchControl.ts#L332-L336 ).

I will raise a new issue. [edit: #384]

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 a pull request may close this issue.

1 participant