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

Using events on form collections including index #210

Closed ScherlOMatic closed 7 years ago

ScherlOMatic commented 7 years ago

Hello!

Thx again for helping me out last time. I ran into a new let's call it problem while adding entities dynamically.

Class structure looks like this: Order has multiple Products. Where products contain the PlaceAutocompleteType. The event is this: function (e) { document.getElementById("order_products___name___place").value = JSON.stringify(this.getPlace()); }

As you can see I need the index of the current colletion within the event. I'm not sure there is an easy method to access the index from within the event. So what I did was to replace the index by a placeholder called "name". This works fine cause also the prototype function from symfony works with it and replaces name dynamically before adding it via javascript.

Sounds great, doesn't it? But the first collection has still the name living inside of the javascript. My workaround to fix it this is not the best so I'm asking for your opinion.

{{ form_row(job.location)|replace({'__name__': loop.index0})|raw }}

place is a hidden variable where i save the google place details into location is the placeautocomplete type

thx for your advice

egeloen commented 7 years ago

@ScherlOMatic Where does come from the event? You put it in your own javascript?

ScherlOMatic commented 7 years ago

Nope, I put it inside my Symfony Form Type. See #196 for more details about the event itself.

egeloen commented 7 years ago

I don't see an easy solution as the prototype coming from symfony does not expose such information to javascript... You will need to live with your "workaround". Closing for now but if someone dig into this issue and find a nicer solution, share it :)