Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form] adding the ChoiceView as a var for expanded choices sub forms #5286

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

Closed
bamarni opened this issue Aug 17, 2012 · 8 comments
Closed

[Form] adding the ChoiceView as a var for expanded choices sub forms #5286

bamarni opened this issue Aug 17, 2012 · 8 comments

Comments

@bamarni
Copy link
Contributor

bamarni commented Aug 17, 2012

I'm having some difficulties to do a custom rendering for expanded choices. I'm using an entity type wich is ordering entities by a relation table, and for each different relation I have to do a group of chexkboxes, with another one at the top allowing to select all or none of the group.

My issue is that I can't do the correlation between the form views and choice views. So I think it's really complicated to do custom rendering on expanded choices.

I'm suggesting to pass the ChoiceView as a var for each choice subForm so that when iterating on the choice formview we can get access to the choice view data, giving more information to be able to render custom stuffs (when the original data is an object).

@webmozart
Copy link
Contributor

Thank you for taking the time to report this issue! What information does ChoiceView provide that you cannot access via FormView?

See also #4171.

@bamarni
Copy link
Contributor Author

bamarni commented Oct 19, 2012

This information is the ChoiceView's 'data' property.

In my use case, it was an entity type, so this property contained an
object, in the query builder I was ordering them by category, and my
goal was to be able to render them as groups of checkboxes.

So in my custom theme when iterating over the forms I was expecting a
way to somehow access the original data, and then you know whenever the
category changes I would start to render another section (eg. put them
in another div tag), but I couldn't as this information is only under
the 'choices' var. And I could't find a way to do the correlation
between a FormView and its related ChoiceView.

@corphi
Copy link
Contributor

corphi commented Feb 28, 2013

I had a similar task and managed to get the corresponding entity in form.vars.choices[child.vars.value].data; if form is the entity widget and child the current child. Some more obvious places don’t work:

  • form.vars.data - array (or alike) only containing checked entries’ entities
  • child.vars.data - empty (this should be changed imho)
  • child.vars.choice - index missing

(Disclaimer: Maybe I included mistakes; didn’t remember my GitHub password and thus couldn’t login from work.)

ruian added a commit to ruian/symfony that referenced this issue Dec 4, 2013
Description:
Because some times is usefull to add some attributes to select's options. Exemple when using, select2, chosen, or juste by adding some prototypes.

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony#5286
| License       | MIT
ruian added a commit to ruian/symfony that referenced this issue Dec 16, 2013
Description:
Because some times is usefull to add some attributes to select's options. Exemple when using, select2, chosen, or juste by adding some prototypes.

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony#5286
| License       | MIT
ruian added a commit to ruian/symfony that referenced this issue Jan 7, 2014
Description:
Because some times is usefull to add some attributes to select's options. Exemple when using, select2, chosen, or juste by adding some prototypes.

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony#5286
| License       | MIT
@hugohenrique
Copy link
Contributor

Any news on this problem?

@hugohenrique
Copy link
Contributor

ping @webmozart

@hugohenrique
Copy link
Contributor

I was unable to access this way: {{ form.field.vars.choices[id].data.attribute }}

@kokmok
Copy link

kokmok commented Apr 22, 2014

His solution worked perfectly for me :
{%for child in form%}
{% set entity = form.vars.choices[child.vars.value].data %}
{%endfor%}

@webmozart
Copy link
Contributor

I think this is a duplicate of #5489.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants