I
I
Igor Surname2019-09-15 19:19:28
symfony
Igor Surname, 2019-09-15 19:19:28

How to apply css for Symfony Form?

There is a template with html + css form, I need to convert the form to symofony form. There is a radio button in the form, initially it looked like this:

<div class="currency-label">
                <input checked id="cur1" name="currency" type="radio">
                <label for="cur1">RUB</label>
            </div>
            <div class="currency-label active">
                <input id="cur2" name="currency" type="radio">
                <label for="cur2">USD</label>
            </div>

, I created in my symfony form:
->add(
                'vacancyCurrency',
                ChoiceType::class,
                [
                    'choices' => [
                        'usd' => 'USD',
                        'eur' => 'EUR',
                    ],
                    'expanded' => true
                ]
            )

and in template:
{{ form_widget(form.vacancyCurrency, {'attr':
                                            {'class': 'currency-label'}
                                        }) }}

but it breaks my css. 'class':'currency-label' applies to the whole widget, how to separate each option i.e. `USD` and `EURO` to your ` ` tag? <div>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Igor Surname, 2019-09-19
@Morilon

Posted an answer on Stackoverflow: https://stackoverflow.com/questions/57914944/how-t...

P
postgresdev, 2019-09-18
@postgresdev

Instructions:
1. You need to access the field in the loop(In my case, through the related form)
Code of the view:

{% for systemItem in form.accountSetting.eprocurementSystemUsed.vars.form.children %}
    <div>
        {{ form_widget(systemItem) }}
        {{ form_label(systemItem) }}
    </div>
{% endfor %}

Code of the form:
->add('eprocurementSystemUsed', ChoiceType::class, [
'choices' => [
'Ariba' => AccountSetting::EPROCURMENT_SYSYTEM_ARIBA,
'Proactis' => AccountSetting::EPROCURMENT_SYSYTEM_PROACTIS,
'Coupa' => AccountSetting::EPROCURMENT_SYSYTEM_COUPA,
'Newtron' => AccountSetting::EPROCURMENT_SYSYTEM_NEWTRON,
'SAP' => AccountSetting::EPROCURMENT_SYSYTEM_SAP,
'Other' => AccountSetting::EPROCURMENT_SYSYTEM_OTHER,
'Oracle' => AccountSetting::EPROCURMENT_SYSYTEM_ORACLE
,
'expanded' => true,
'multiple' => false,
'empty_data' => null,
'required' => false,
])
Results: input and label in div.

D
Denis Derepko, 2019-09-17
@uDenX

How to Customize Form Rendering

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question