KeyValueFormBundle icon indicating copy to clipboard operation
KeyValueFormBundle copied to clipboard

[Question] How to render line instead of block

Open mpoiriert opened this issue 4 years ago • 3 comments

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...

mpoiriert avatar Dec 07 '19 04:12 mpoiriert

@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.

hacfi avatar Dec 15 '19 18:12 hacfi

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 [email protected] 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 .

mpoiriert avatar Dec 15 '19 19:12 mpoiriert

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

hacfi avatar Dec 15 '19 19:12 hacfi