0

I want to display a database value in a checkbox, during add and edit time

Here is my code which displays values in combobox

public function buildForm(FormBuilderInterface $builder, array $options)
{

    $builder->add('role', 'entity', array(
    'class'         => 'DashboardAdminManageUserBundle:role',
    'property'      => 'title',
    'multiple'      => true,
    'query_builder' => function(EntityRepository $er) {
        return $er->createQueryBuilder('g');

    },
    'label'    => 'Role*:',
    'by_reference' => false,
    'required' => false,
    ));



}

So how do you display the same values in a Checkbox?

0

2 Answers 2

2

You should use the expanded option and set it to true. Take a look at the documentation for more informations.

$builder->add('role', 'entity', array(
    'class'    => 'DashboardAdminManageUserBundle:role',
    'property' => 'title',
    'expanded' => true,
    'multiple' => true,
    'label'    => 'Role*:',
    'required' => false,

    // Add custom html attribute
    'attr'     => array('class' => 'my-class'),
));

Then, just need to customize the .my-class input CSS.

Sign up to request clarification or add additional context in comments.

4 Comments

it is default check box.. and i want dynamic value from database
It is not clear what do you call dynamic value from database? If you use this configuration all checkbox have a dynamix value which comes from the database (using the title property of the DashboardAdminManageUserBundle:role class).
pl give me one example for the same
gelo thanks for help but one question check box is not display properly how to add css in checkbox
1

Select tag, Checkboxes or Radio Buttons field may be rendered as one of several different HTML fields, depending on the expanded and multiple options:

select tag => expanded = false ,multiple = false

select tag (with multiple attribute) => expanded = false, multiple = true

radio buttons => expanded = true, multiple = false

checkboxes => expanded = true, multiple = true

Refer this table for your requirement

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.