egeloen / IvoryGoogleMapBundle

Google Map API v3 integration for your Symfony2 project.
https://github.com/egeloen/ivory-google-map
MIT License
217 stars 152 forks source link

Autocomplete Form Submission #129

Closed soerenmartius closed 8 years ago

soerenmartius commented 9 years ago

Hi,

Whats the best way to submit the current form after a list entry was chosen? I dont want users to have to click on a submit button if the form only contains the places autocomplete field.

Thank you

egeloen commented 9 years ago

Thx for reporting this! Basically, I would say you should use events. The problem is the events are only usable with a map... I think we should add this feature to the places autocomplete too.

For now, if you're using the places autocomplete as standalone, you can override the twig form block and append your own js line (See https://developers.google.com/maps/documentation/javascript/events for how using the places autocomplete events).

egeloen commented 8 years ago

Your issue has been fixed in #159 but will only be part of the 3.x version of the bundle.

As already suggested, the solution is to use events. Something like the following would do the job:

$builder->add('field', PlaceAutocompleteType::class, [
    'variable' => $variable = 'acme_place_autocomplete',
    'events' => [new Event(
        $variable,
        'place_changed',
        'function () { /* Handle your automatic form submission... */ }'
    )]
]);