8000 [Form] New Page "How to Add Information to Individual Radio Buttons" · Issue #13562 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[Form] New Page "How to Add Information to Individual Radio Buttons" #13562

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
ThomasLandauer opened this issue Apr 18, 2020 · 3 comments
Closed

Comments

@ThomasLandauer
Copy link
Contributor

Following up on symfony/symfony#36484 (comment) I'm starting to collect some ideas here.

@HeahDude I don't think that https://symfony.com/doc/current/form/create_custom_field_type.html is the right place, for two reasons:

  • We are not creating a custom form type :-) We're just manipulating the existing ChoiceType with finishView()
  • The question people are having is about their radio buttons. They probably will not look into something called "Custom Form Field Type".

So I'm suggesting to add a page called "How to Add Information to Individual Radio Buttons" to the list at https://symfony.com/doc/current/forms.html#learn-more under "Advanced Features"

Taking the example from https://symfony.com/doc/current/reference/forms/types/choice.html#advanced-example-with-objects the code would look like this:

$builder->add('category', ChoiceType::class, [
    'choices' => $this->categoryRepository->findAll(),
    'choice_value' => 'id',
    'choice_label' => 'name',
    'choice_name' => 'id',
]);

public function finishView(FormView $view, FormInterface $form, array $options)
{
    foreach($this->categoryRepository->findAll() as $category)
    {
        $view['category'][$category->getId()]->vars['more_info'] = $category->getMoreInfo();
    }
}

Add something like this to {% block checkbox_radio_label -%} in your form theme:

    {%- if more_info is defined %}
        {{ more_info }}
    {% endif -%}

Questions:

  1. To which other widgets (besides radio buttons) does this apply to?
  2. Am I right that we need to query the repository in finishView again? There's no easier way than iterating over all of them?
@xabbuh xabbuh added the Form label Apr 21, 2020
@carsonbot
Copy link
Collaborator

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

@carsonbot
Copy link
Collaborator

Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3

@carsonbot
Copy link
Collaborator

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

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

3 participants
0