symfony-forms

Symfony 2.6 - render individual choice field (radio, checkbox) by name

泄露秘密 提交于 2020-01-01 02:46:07
问题 How can I render an individual field (single radio/checkbox input field) in Twig in Symfony 2.6? Let's say I have a simple form: class TransportType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('transport', 'choice', array( 'choices' => array( 'road' => 'Car/bus', 'train' => 'Train', ), 'expanded' => true, 'multiple' => false )); } In previous Symfony2 versions I could just use: {{ form_widget(form.transport.road) }} {{ form

Get options of an entity Field in twig

和自甴很熟 提交于 2019-12-31 07:11:18
问题 I have an entity field that is passed to twig view, It is rendered and works fine. Is it possible to get the <option> values of that field and render them somewhere else ( I need another select with the same values of that entity field >. say this is my entity field {{ form_widget(entity_field) }} I want something like this <select id="just_another_select"> {% for value in entity_field.values %} <- how to get entity_field.values <option > value </option> {% endfor %} 回答1: Yes you can get all

Symfony2 entity field type alternatives to “property” or “__toString()”?

你说的曾经没有我的故事 提交于 2019-12-29 03:10:29
问题 Using Symfony2 entity field type one should specify property option: $builder->add('customers', 'entity', array( 'multiple' => true, 'class' => 'AcmeHelloBundle:Customer', 'property' => 'first', )); But sometimes this is not sufficient: think about two customers with the same name, so display the email (unique) would be mandatory. Another possibility is to implement __toString() into the model: class Customer { public $first, $last, $email; public function __toString() { return sprintf('%s %s

Symfony2: List Users with Option to Deactivate Each User

牧云@^-^@ 提交于 2019-12-25 12:42:55
问题 In my application's admin panel, I am showing a list of users who are currently marked as "Active" in the database. <ul class="list-group"> {% for activeuser in activeusers %} <li class="list-group-item"> {{ activeuser.username|e }} <input type="checkbox" name="my-checkbox" class="ckbx" checked> </li> {% endfor %} </ul> As you can see, each active user list item has a placeholder checkbox for now which is checked when the user is, you guessed it, active. I would like to be able to simply

Symfony2: List Users with Option to Deactivate Each User

南楼画角 提交于 2019-12-25 12:42:08
问题 In my application's admin panel, I am showing a list of users who are currently marked as "Active" in the database. <ul class="list-group"> {% for activeuser in activeusers %} <li class="list-group-item"> {{ activeuser.username|e }} <input type="checkbox" name="my-checkbox" class="ckbx" checked> </li> {% endfor %} </ul> As you can see, each active user list item has a placeholder checkbox for now which is checked when the user is, you guessed it, active. I would like to be able to simply

How Can I add get container in form builder symfony?

帅比萌擦擦* 提交于 2019-12-25 11:56:27
问题 How Can I add get container in form builder symfony ? I would like use $get->container in form builder... 回答1: Injecting the whole container into a form type is a bad practice. Please consider injecting only required dependencies to your form type. You can simply define your form type as a service and inject required dependencies. src/AppBundle/Form/TaskType.php use Doctrine\ORM\EntityManagerInterface; // ... class TaskType extends AbstractType { private $em; public function __construct

Symfony, how to use form event to validate dynamic client-side form

自闭症网瘾萝莉.ら 提交于 2019-12-25 10:40:51
问题 I'm using the select2 plugin with ajax to have a dynamic field on my form, but when i submit the it return me an error "This value is not valid" , which is normal cause i use the ChoiceType with an empty array() in the choices options on creation. According to this part of the symfony doc, the form event is my savior, so trying to use it but it look like something wrong with my code and can't really see what. So My Question Is : HOW to pass the choices possibility to the field, for the form

Form theming and Symfony Collections

…衆ロ難τιáo~ 提交于 2019-12-25 07:53:04
问题 I wanted to add particular style to my CollectionType in twig and I received a solution here : Symfony/Jquery Collection of objects. Now I have a little problem that I can't solve : I have this custom form_row : // src/MyBundle/Ressources/views/CustomForms {% block form_row %} <div class="row"> <div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}"> <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12"> {{- form_label(form, "", {'label_attr

Symfony 2: Dynamic Form Event returns InvalidArgumentException only when editing

余生颓废 提交于 2019-12-25 07:07:46
问题 I got an entity called 'Activity', that defines a relation between 2 more entities, 'Service' and 'Location'. Both 'Service' and 'Location', use another entity called 'Allocation', to define what services can be used in a concrete location. When I create a new Activity, after selecting a service I want the location choice field update with the values defined by allocation. I have followed symfony documentation to create this 'location' dependent choice field in the form. Dynamic Form

Symfony DataTransformers with choice forms

对着背影说爱祢 提交于 2019-12-25 02:55:09
问题 I made a DataTransformer that is made to basically NOT the available choices with the submitted ones. My issue is that my transformer receives either ['INFO' => 'INFO', 'WARN' => 'WARN'] or [0 => 'INFO', 1 => 'WARN'] . This usually happens when all the checkboxes are unchecked (AKA the model data of the choice is ['INFO', 'WARN']) and that I check any and submit the form. I am using Symfony 2.6.6. Here is the form : $choice = $builder->create('choice', 'choice', array( 'choices' => array(