symfony2 twig render form 'choice' as list - forms

How can I (in symfony2 twig) render the form control 'choice' (expanded, checkboxes) as list ('li's, or just with a 'br' inbetwwen each option) and not have all options appear on one line?
I guess I could bach a jQuery together, but isn't there a more native way?

You can override the appropriate theme block. There is a great description in the docs how to do that.

Related

Pass dato between Actions - Symfony 2.6

well I have some problems to pass data between actions...
I have a actions that have a form, this form only have 2 element, a text area and a radiobutton.
well, I need pass the text and choice to other action and show this text and this choice... I try whit manual of symfony but I don't see how to make...
Thanks !

Can you use Chosen with dynamically created form elements?

I've created a simple form containing two selectbox elements. I also have a button which dynamically adds these selectboxes at the user's discretion. The selectbox options will be quite long, so I've applied the jQuery Chosen plugin to be more useful.
Everything works fine until a new element is dynamically added using jQuery clone. I am unable to select any options in my new element selectboxes, and they also carry the prior results.
In searching the forum, others have 'reset' Chosen after a selection, by calling: $("#form_field").trigger("liszt:updated"); . I tried this as well, but it will just clear all the selections (which I don't want) and continue to freeze the dropdown action.
Anyone have experience with using Chosen (or any other autocomplete-type selectbox enhancement) with dynamic elements?
Found a solution that works - albeit without using the Chosen plugin.
I changed my dynamically created form elements by replacing the selectboxes with input fields tied to a basic jQueryUI autocomplete plugin. Here is a link to their implementation : http://jqueryui.com/autocomplete/#default.
The main difference is that the select "options" in this case, were listed as the source from which the box would look for autocomplete options. My list was 70 items long, so the initial setup took some time.
The jQuery text was generically as follows:
$("input#search").autocomplete({
source: [item1, item2, item3, item 4, ... item5]);

Specify the form theme of a specified entity in Symfony 2

I am working on a form quite complicated.
This form is based on an OngletFichier Entity with its form Builder :
$builder
->add('traitement')
->add('ligneEntetes');
$builder->add('colonnesOnglet', 'collection', array('type' => new ColonneOngletType()
));
As you can see, in this Entity Form, I got a list of ColonneOnglet which is an other entity.
It looks like something like that :
Entity Form
SimpleAttribute of OngletFichier (text input)
SimpleAttribute of OngletFichier (text input)
ColonneOnglet (which have its own attributes, its own input)
ColonneOnglet (which have its own attributes, its own input)
ColonneOnglet (which have its own attributes, its own input)
I need to define a special form theme for each ColonneOnglet to organize its inputs, and to put it in red or not depending on one of its attribute.
I am quite lost with form theming.
I found an example but I don't know if it can answer my problem : http://symfony2-document.readthedocs.org/en/latest/cookbook/form/create_custom_field_type.html
Thanks in advance for helping me !
EDIT :
http://symfony.com/doc/current/cookbook/form/form_customization.html#how-to-customize-an-individual-field
This works easily !
The article you've found is good, but I think this section of the manual fits better: http://symfony.com/doc/2.0/cookbook/form/form_customization.html#how-to-customize-an-individual-field
So the easiest way is to create separate file with form theme and import it into template using
form_theme form 'Path:To:theme.html.twig'. You can also define your styling inside the template itself and import using this directive: form_theme form _self, but be aware that in order for this to work the template must extend another one.

Symfony 1.4 - are forms always in <table>?

I'm using sfDoctrineAllowPlugin. I need form which has Twitter's Bootstrap semantics. I looked into template and I found, that there is only $form, which is a <table>. How can I format it in my way? I don't want to use table, rows and cols.
There are plenty of render* functions available to display each item in your form.
renderRow
renderLabel
render
renderError
etc ...
But you can also define a decorator (a custom sfWidgetFormSchemaFormatter) for your form to define the way each item will be display. Check this example of adding * for each required field.

CakePHP DIV option for Dropdowns

It's easy to configure a Div using the form helper for standard input boxes. An example int he manual is...
echo $this->Form->input('User.name', array('div' => 'class_name'));
However, I can't achieve the same thing with dropdown menus?
Can anyone help out as to how to wrap a dropdown with a DIV using the form helper method?
thanks
I imagine you've been building your dropdowns with FormHelper::select, which doesn't include all the sugar of FormHelper::input, like automatic <div /> wrapping, magic error-messages, etc. You can get FormHelper::input to output a dropdown using the following.
$this->Form->input(
'User.country',
array(
'options'=>$arrayOfCountries,
'div'=>'class_name'
)
);
The options parameter indicates to FormHelper::input that you want a dropdown. You could achieve the same effect with the type parameter (ie. 'type'=>'select'), but the options parameter gives the same effect while also taking care of preparing the dropdown's options.