Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two buttons in a row (Bootstrap form theme for Symfony2)

I'm using the Bootstrap form theme for Symfony2 (bootstrap_3_horizontal_layout.html.twig):

I've added two buttons on a form:

$builder
    // some code here ... 
    ->add('save', 'submit', ['label' => 'save'])
    ->add('cancel', 'submit', ['label' => 'cancel']);

And they are rendered this way: enter image description here

I need that they be situated on the same row: enter image description here

How can it be achieved?

like image 679
Vasily Avatar asked Feb 09 '23 09:02

Vasily


2 Answers

Following the

Symfony Best Practises: Add buttons in the templates, not in the form classes or the controllers.

E.g.:

{{ form_start(form) }}
  {{ form_widget(form) }}

  <div class="row">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" value="save" class="btn btn-primary">save</button>
      <button type="submit" value="cancel" class="btn btn-default">cancel</button>
    </div>
  </div>
{{ form_end(form) }}
like image 192
Yoshi Avatar answered Feb 12 '23 03:02

Yoshi


Just add a style float left to the save button. This works for me:

    ->add('save', 'submit', ['label' => 'save', 'attr' => array('style' => 'float: left')])
    ->add('cancel', 'submit', ['label' => 'cancel']);
like image 28
Matteo Avatar answered Feb 12 '23 02:02

Matteo