Comments (4)
I have the same needs. This stackoverflow post helped me: https://stackoverflow.com/questions/11388251/google-autocomplete-enter-to-select.
from ngx-google-places-autocomplete.
This should be an open issue because it's easy to fix if you are inside the Google directive. I'd argue really this should be fixed inside the underlying Google component because it'll happen for them as well outside of angular. But this is what I did to work around it. Inside the component holding the form element I looked for the enter key bubbling up. I'm checking where the key event came from so that hitting enter would still allow the form to be submitted if used in other fields, but if used on the places component it won't submit the form automatically.
@ViewChild( 'street', { read: ElementRef} ) streetElem : ElementRef;
@HostListener('keydown', ['$event'])
handleKeyboardEvent( event : KeyboardEvent ) {
// this prevents places component from submitting the form when using enter
let key = event.key.toLowerCase();
if( key == 'enter' && event.target === this.streetElem.nativeElement ) {
event.preventDefault();
event.stopPropagation();
}
}
from ngx-google-places-autocomplete.
Fixed in 2.0.3
from ngx-google-places-autocomplete.
@skynet2 With Chrome's built in autocomplete the code submitted in 2.0.3 will produce an error when the user clicks on the address suggested by the browser.
This can be fixed by wrapping the code in a if( "key" in event ){}
I believe the code snippet below should resolve this issue.
@HostListener('keydown', ['$event'])
handleKeyboardEvent( event : KeyboardEvent ) {
// this prevents places component from submitting the form when using enter
if( "key" in event ){
let key = event.key.toLowerCase();
if( key == 'enter' && event.target === this.streetElem.nativeElement ) {
event.preventDefault();
event.stopPropagation();
}
}
}
from ngx-google-places-autocomplete.
Related Issues (20)
- Debounce time during type a text
- How can I set the HTML5 'autocomplete' value to something different to 'off'
- How TO change componentRestrictions -- Country Dynamically? HOT 4
- Testing Error With Angular 12
- Is project is still active ? what about angular 13 support HOT 1
- more than 1 input in the same component
- ERROR ReferenceError: google is not defined HOT 2
- Initialize with code instead of tag
- No directive found with exportAs 'ngx-places'.
- "google is not defined" in Angular 13 HOT 1
- Cannot Restrict Countries HOT 3
- There is no support for Angular 16! HOT 7
- Safari - iOS: When selecting the autocomplete address, it is not selected
- Not compatible with Angular 16 HOT 1
- When this library trigger google services?
- google map Key move from index.html HOT 1
- Dropdown Not Showing HOT 5
- Options Error - All fields required HOT 2
- Issues Returning Certain Addresses HOT 1
- Warning: CommonJS or AMD dependencies can cause optimization bailouts HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngx-google-places-autocomplete.