This is my Formtype
->add('dateNaissance', 'date', array(
'required' => true,
'widget' => 'choice',
'years' => range(date('Y') - 100, date('Y') ),
))
->add('type', 'hidden', array(
'mapped' => false,
));
and i fixed my range like this but i want to get 3 different range in my formwidget older, younger and baby it is possible to change range in form_widget ?
For example can i give a parameter here to change my range
{{ form_widget(adulte.dateNaissance.year,
{'attr': {
'class': 'form-control pull-left birthdate-y-coordonnees'
}}
)}}
Related
I got the error :
Neither the property "amount" nor one of the methods "amount()", "getamount()"/"isamount()" or "__call()" exist and have public access in class "Symfony\Component\Form\FormView".
when I try to get the form field using "prototype" in a Form template.
Form Template:
{% block proposal_service_widget %}
{% set prototype_html = '<td>' ~ form_widget(prototype.amount) ~
'</td>' %}
The Entities are Proposal, Service and ProposalService
For ProposalType I have an option "proposal_service" as true, and the form template is identifying this option.
->add('services', BootstrapCollectionType::class, [
'label' => 'Services:',
'type' => ProposalServiceType::class,
'proposal_service' => true,
'prototype' => true,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'sub_widget_col' => 10,
'button_col' => 2,
'add_button_text' => 'Add Service',
]);
My question is Why the Form Template is not identifying the "prototype.amount" ????
if I have this field on my ProposalServiceType ??
$builder
->add('amount', null, [
'label' => 'Qty:',
'attr' => ['class' => 'amount', 'min' => 1]
])
A client doesn't want to scroll in a select form so I need to increase the size of my select form.
I tried this but still doesn't work, I only see 4 inputs :
{{ form_widget(filterForm.accomodationFilter1, { attr: { class: 'fancyselect filter type' }, {'size': '10'} }) }}
Any idea how I can do that and where is the documentation ?
Thanks
Try doing it directly in the formBuilder:
->add('example', 'choice', array(
'attr' => array('class' => 'fancyselect filter type',
'style' => 'max-width:100px'),
'choices' => 'choices',
)
Or just use:
->add('example', 'choice', array(
'attr' => array('class' => 'fancyselect filter type'),
'choices' => 'choices',
'max_length' => 100,
)
I want to disable the empty_value by default in my form type.
how to do this ?
->add('subject', 'choice', array(
'label' => 'Subject',
'choices' => array(
'1' => 'contact.Appreciation',
'2' => 'contact.Feedback',
'3' => 'contact.Dissatisfactions',
'4' => 'contact.My account',
'5' => 'contact.Recruitment',
'6' => 'contact.Other',
),
'attr' => array(
'class' => 'form-control'
),
'required' => false,
'empty_value' => 'contact.Subject',
))
Change required to true.
'required' => true
See documentation
There is no easy solution for this, but you can use an event listener on the PRE_BIND event.
See this for example: https://stackoverflow.com/a/14346520/606104
I have this field,
->add('number', 'number', array(
'label' => false,
'attr' => array('class' => 'producto', 'type' => 'number')))
I expected a type="number" attribute to be added, increase and decrease the number inside with the little arrows down/up, but I get an input with type="text" attribute:
<input type="text" value="11" class="producto form-control" required="required" name="project_backendbundle_pedido[pedidoSubitems][0][number]" id="project_backendbundle_pedido_pedidoSubitems_0_number">
The type attribute is set via the widget type you choose. To get a type="number" you need to choose integer as widget type. Confusing, I know..
But have a look at the official symfony page. So your code should look like this:
->add('number', 'integer', array(
'label' => false,
'attr' => array('class' => 'producto'),
))
To have a type number you need to do(for symfony 2.8):
In form builder use these parameters:
->add('fixedCharge', 'number', array(
'required' => true,
'rounding_mode' => 0,
'precision' => 2,
'scale' => 7,
'attr' => array(
'min' => -90,
'max' => 90,
'step' => 0.01,
),
))
In twig define explicitly as number:
{{ form_widget(form.fixedCharge, { 'type':'number' }) }}
Additionally, for browsers that ignore HTML5 validation, you can also add a server side validation on the entity field:
#Assert\Type(type="float", message="must be a numeric value")
I have a problem with collection from symfony documentation. Here is my code:
controller:
$emails = array("first#qwe.com", "second#qwe.com", "third#qwe.com");
$myDForm = $this->createFormBuilder($emails)
->add('emails', 'collection', array('type' => 'email', 'options' => array('required' => false, 'attr' => array('class' => 'email-box')),))
->GetForm();
$myDForm->handleRequest($request);
twig:
{{ form_start(myDForm) }}
{{ form_end(myDForm) }}
As you can see the code looks easy, there are no errors just an empty page...
Could somebody point me where is the problem? I'm a beginner but it's almost exact as code in doc.
I'd like to make several submit buttons on a form this way but I stuck with this.
Thank you.
First:
Change
GetForm
to
getForm
$emails = array("first#qwe.com", "second#qwe.com", "third#qwe.com");
$myDForm = $this->createFormBuilder($emails)
->add(
'emails',
'collection',
array(
'type' => 'email',
'options' => array('required' => false, 'attr' => array('class' => 'email-box')),)
)->getForm();
$myDForm->handleRequest($request);
I don't know what is your point to use emails with collection.
Second:
You are just opening your form. You are not giving any field to print.
{{ form_start(myDForm) }}
{{ form_row(form.emails) }}
{{ form_end(myDForm) }}
http://symfony.com/doc/current/reference/forms/twig_reference.html