A
A
Alexander2016-11-18 23:20:38
symfony
Alexander, 2016-11-18 23:20:38

How to pull out additional information in the form for a related entity in Symphony2?

there are two entities interconnected
Locations <-> ManyToOne <-> Locationstype
9eb66314b08648babfb919071250516b.png
when I make a form, for example, a new Location
in the Location_type field, thanks to the connection, all values ​​​​from the Locationtype entity are pulled up
06bb203abcd24e5a81087fdd1abc3451.png

<select id="book_fromBookType" name="book[fromBookType]">
<option value=""></option>
<option value="1">Airport</option>
<option value="2">Address</option>
<option value="3">Train Station</option></select>

you need to pull up the data attributes to the option in order to synchronize two selects with each other (I plan to do this with javascript on the client)
to get something like this
<select id="book_fromBookType" name="book[fromBookType]">
<option value=""></option>
<option value="1" data-type="air">Airport</option>
<option value="2" data-type="adr">Address</option>
<option value="3" data-type="train">Train Station</option>
</select>

<select>
<option value=""></option>
<option value="1" data-type="air">Аэропорт Домодедово</option>
<option value="2" data-type="adr">Гдето там</option>
<option value="3" data-type="train">Киевский вокзал</option>
<option value="4" data-type="train">Ярославский вокзал</option>
</select>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Netesin, 2016-11-19
@knetesin

- you can add attributes like this :)
- or customize the output template, dock on the topic , and more specifically choice_widget_options + apply to the field like this

A
Axian Ltd., 2017-02-23
@AxianLTD

Well, where do you declare client and is_array in your class?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question