Burgov / KeyValueFormBundle

A form type for managing key-value pairs
MIT License
44 stars 32 forks source link

[Question] How to render line instead of block #34

Open mpoiriert opened 4 years ago

mpoiriert commented 4 years ago

This is not a issue with the bundle itself but I was wondering if you know how to easily render the form as a row instead of a block.

This is how I would want to it to look like (this is a override of a row rendering I did in sonata) Screenshot from 2019-12-06 23-42-02

And this is the default rendering of your component:

Screenshot from 2019-12-06 23-42-34

Maybe there is a generic solution (class, css, configurion) I don't want to end up overriding with {% block {form_input_name}_row %} for all the input I need to do so...

hacfi commented 4 years ago

@mpoiriert You can iterate over the field and customize rendering in the template itself:

      {% for field in form.parameters %}
        <div>
          <div><button>-</button></div>
          <div>{{ form_row(field.key) }}</div>
          <div>{{ form_row(field.value) }}</div>
        </div>
      {% endfor %}

Of course form.parameters will be different in your case..maybe passenger_form.adults or whatever you pass from the controller to the template and whatever your form field is called.

mpoiriert commented 4 years ago

I was trying to find a generic solution without needing to do something specific every time.

On Sun, Dec 15, 2019, 1:17 PM hacfi notifications@github.com wrote:

@mpoiriert https://github.com/mpoiriert You can iterate over the field and customize rendering in the template itself:

  {% for field in form.parameters %}
    <div>
      <div><button>-</button></div>
      <div>{{ form_row(field.key) }}</div>
      <div>{{ form_row(field.value) }}</div>
    </div>
  {% endfor %}

Of course form.parameters will be different in your case..maybe passenger_form.adults or whatever you pass from the controller to the template and whatever your form field is called.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Burgov/KeyValueFormBundle/issues/34?email_source=notifications&email_token=AA73OADR6SMSJPAFL73UYC3QYZYEHA5CNFSM4JXHUV2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEG4626Q#issuecomment-565833082, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA73OACYW24I4BYP4X2YYCLQYZYEHANCNFSM4JXHUV2A .

hacfi commented 4 years ago

There is no way to tell if the rendered fields are Key Value pairs from this bundle or just regular text fields that should be rendered so it's impossible to achieve what you describe. But maybe a Twig macro makes this more elegant: https://twig.symfony.com/doc/3.x/tags/macro.html