Could not load type "locality" - symfony

I hope to use a form inside my controller,but I get everytime the following error :
Could not load type "locality"
and here is ly form class :
class LocationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$factory = $builder->getFormFactory();
$builder->add('province','entity',array(
'class' => 'Acme\DemoBundle\Entity\Province',
'property' => 'name'));
$refreshLocality = function ($form, $province) use ($factory) {
$form->add($factory->createNamed('entity','locality',null, array(
'class' => 'Acme\DemoBundle\Entity\Locality',
'property' => 'name',
'label' => 'Locality',
'query_builder' => function (EntityRepository $repository) use ($province) {
$qb = $repository->createQueryBuilder('locality')
->innerJoin('locality.province', 'province');
if($province instanceof Province) {
$qb = $qb->where('locality.province = :province')
->setParameter('province', $province);
} elseif(is_numeric($province)) {
$qb = $qb->where('province.id = :province_id')
->setParameter('province_id', $province);
} else {
$qb = $qb->where('province.id = 1');
}
return $qb;
}
)));
};
$builder->add('address','text',array(
'required' => false));
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($refreshLocality) {
$form = $event->getForm();
$data = $event->getData();
if($data == null)
$refreshLocality($form, null); //As of beta2, when a form is created setData(null) is called first
if($data instanceof Location) {
$refreshLocality($form, $data->getLocality()->getProvince());
}
});
$builder->addEventListener(FormEvents::PRE_BIND, function (FormEvent $event) use ($refreshLocality) {
$form = $event->getForm();
$data = $event->getData();
if(array_key_exists('province', $data)) {
$refreshLocality($form, $data['province']);
}
});
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Acme\DemoBundle\Entity\Location'
));
}
public function getName()
{
return 'acme_demobundle_locationtype';
}
}
Then I called this class in my controller :
public function indexAction()
{
$form = $this->get('form.factory')->create(new \Acme\DemoBundle\Form\LocationType());
$request = $this->get('request');
if ($request->isMethod('POST')) {
$form->bind($request);
if ($form->isValid()) {
}
}
return array('form' => $form->createView());;
}
and here my twig :
<form action="{{ path('_demo') }}" method="POST" id="contact_form">
{{ form_errors(form) }}
{{ form_rest(form) }}
<input type="submit" value="Send" class="symfony-button-grey" />
</form>
when I had the error above I tried to register your form in the section services in service.xml :
<service id="form.type.acme_demobundle_locationtype" class="Acme\DemoBundle\Form\LocationType">
<tag name="form.type" alias="acme_demobundle_locationtype" />
</service>
but I get the same error,any idea?

You need to swap the arguments that you passed to createNamed():
$form->add($factory->createNamed('entity','locality',null, array(
should be
$form->add($factory->createNamed('locality', 'entity', null, array(
In fact, you can even simplify your code to
$form->add('locality', 'entity', array(

Related

Symfony2 - Dynamic generated form not working while editing form

Based on documentation: http://symfony.com/doc/2.8/form/dynamic_form_modification.html#form-events-submitted-data
I prepared dynamic generated form. And everything works properly but only when I use form for adding new data (/new) when I use the same form for editing existing data - not working
Simple form for "Appointment". It should work like that: User select client and then second "select" is filling proper data - depends on each client from first select. And this works ok but only when I try add new Appointment. When I try edit no.
class AppointmentType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name')
->add('client', EntityType::class, array(
'class' => 'SystemAdminBundle:Client',
'placeholder' => '',
));
$formModifier = function(\Symfony\Component\Form\FormInterface $form, Client $client)
{
$diseases = array();
if($client !== null) {
$diseases = $client->getDiseases();
}
$form->add('disease', EntityType::class, array(
'class' => 'SystemAdminBundle:Disease',
'placeholder' => '',
'choices' => $diseases,
));
};
$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function (FormEvent $event) use ($formModifier) {
$data = $event->getData();
$formModifier($event->getForm(), $data->getClient());
}
);
$builder->get('client')->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event) use ($formModifier) {
$client = $event->getForm()->getData();
$formModifier($event->getForm()->getParent(), $client);
}
);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'System\AdminBundle\Entity\Appointment'
));
}
}
Appointment controller - here is function for add new appointment and edit. For "new" my code works, for "edit" no.
public function newAction(Request $request)
{
$appointment = new Appointment();
$form = $this->createForm(AppointmentType::class, $appointment);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $request->request->get('appointment');
if(array_key_exists('name', $data)) {
$em = $this->getDoctrine()->getManager();
$em->persist($appointment);
$em->flush();
return $this->redirectToRoute('appointment_show', array('id' => $appointment->getId()));
}
}
return $this->render('appointment/new.html.twig', array(
'appointment' => $appointment,
'form' => $form->createView(),
));
}
public function editAction(Request $request, Appointment $appointment)
{
$deleteForm = $this->createDeleteForm($appointment);
$appointment = new Appointment();
$editForm = $this->createForm('System\AdminBundle\Form\AppointmentType', $appointment);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$data = $request->request->get('appointment');
if(array_key_exists('name', $data)) {
$em = $this->getDoctrine()->getManager();
$em->persist($appointment);
$em->flush();
return $this->redirectToRoute('appointment_show', array('id' => $appointment->getId()));
}
return $this->redirectToRoute('appointment_edit', array('id' => $appointment->getId()));
}
return $this->render('appointment/edit.html.twig', array(
'appointment' => $appointment,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
View for "new" appointment
{% block content %}
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}
window.onload = function() {
var $sport = $('#appointment_client');
$sport.change(function() {
var $form = $(this).closest('form');
var data = {};
data[$sport.attr('name')] = $sport.val();
data['appointment[_token]'] = $('#appointment__token').val();
$.ajax({
url : $form.attr('action'),
type: $form.attr('method'),
data : data,
success: function(html) {
$('#appointment_disease').replaceWith(
$(html).find('#appointment_disease')
);
}
});
});
};
{% endblock %}
View for "edit" appointment - it's almost the same as for "new" appointment
{% block content %}
{{ form_start(edit_form) }}
{{ form_widget(edit_form) }}
{{ form_end(edit_form) }}
window.onload = function() {
var $sport = $('#appointment_client');
$sport.change(function() {
var $form = $(this).closest('form');
var data = {};
data[$sport.attr('name')] = $sport.val();
data['appointment[_token]'] = $('#appointment__token').val();
$.ajax({
url : $form.attr('action'),
type: $form.attr('method'),
data : data,
success: function(html) {
$('#appointment_disease').replaceWith(
$(html).find('#appointment_disease')
);
}
});
});
};
{% endblock %}
You create a new Appointment in your editAction and then persist it. You should take the one that's in your function parameters, handle the request and just flush, since your object is already persisted.
So remove these lines :
$appointment = new Appointment();
// ...
$em->persist($appointment);

how to dynamically set cascade validation of form from controller

My form looks like this :
class CpanelRetailerForm extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('name', 'text', array(
'attr' => array(
'class' => 'text-input',
'size' => '50'
),
'required' => false
))
->add('email', 'email', array(
'attr' => array(
'class' => 'text-input',
'size' => '50'
),
'required' => false
))
->add('addUser', 'checkbox', array(
'label' => 'Add User account',
'required' => false,
'mapped' => false
))
->add('user',new CpanelUserForm());
}
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'data_class' => 'Acme\TestBundle\Entity\Retailer',
//'cascade_validation' => true
));
}
public function getName() {
return 'retailer';
}
}
I want to dynamically set this line from controller depending on whether addUser field is checked or unchecked.
cascade_validation' => true
Here is my controller code:
$form = $this->createForm(new CpanelRetailerForm(), new Retailer());
$form->
if ($this->getRequest()->isMethod('POST')) {
$form->bind($this->getRequest());
if ($form->get('addUser')->getData()) {
// then set the cascade_validation to true here
}
}
How can I do this inside controller?
My attempt :
added this line in my form class:
$builder->addEventListener(
FormEvents::POST_SUBMIT, function(FormEvent $event) {
$form = $event->getForm();
$addUser = $form->get('addUser')->getData();
$validation = false;
if ($addUser) {
$validation = true;
}
$resolver = new OptionsResolver();
$resolver->setDefaults(array(
'cascade_validation' => $validation
));
$this->setDefaultOptions($resolver);
}
);
This didnot work for me. Although I receive data in $addUser, cascade_validation is not added
How can I do this inside controller?
You can´t! Thats the simple answer. Lets take a look at following simple form class:
class TestType extends AbstractType {
/**
* #var boolean
*/
private $myOption;
/**
* #param FormBuilderInterface $builder
* #param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options) {
$this->myOption = false;
$builder
->addEventListener(FormEvents::POST_SET_DATA, function(FormEvent $event) {
dump('formEvents::PRE_SET_DATA');
})
->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) {
dump('FormEvents::POST_SET_DATA');
})
->addEventListener(FormEvents::PRE_SUBMIT, function(FormEvent $event) {
dump('FormEvents::PRE_SUBMIT');
})
->addEventListener(FormEvents::SUBMIT, function(FormEvent $event) {
dump('FormEvents::SUBMIT');
})
->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event) {
dump('formEvents::POST_SUBMIT');
})
->add('name', TextType::class)
->add('send', SubmitType::class);
}
/**
* #param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver) {
$resolver->setRequired(array(
'my_option'
));
$resolver->setDefaults(array(
'my_option' => $this->setMyOption()
));
}
/**
* #return bool
*/
public function setMyOption() {
dump($this->myOption);
return $this->myOption;
}
}
Lets take in how you render and handle a form inside a Controller:
public function formAction(Request $request) {
$form = $this->createForm(TestType::class);
dump('calledCreateForm');
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()) {
dump('finished');
dump($form->getData());
die();
}
return $this->render('#TestPra/Test/test_form.html.twig', array(
'form' => $form->createView()
));
}
After submitting the form you get the following output order:
$this->setMyOption() > null
FormEvents::PRE_SET_DATA
FormEvents::POST_SET_DATA
calledCreateForm
FormEvents::PRE_SUBMIT
FormEvents::SUBMIT
FormEvents::POST_SUBMIT
finished
The first thing allways gets called is configureOptions and because you don´t have any data of the filled form before calling handleRequest there is no way to change the options of the allready created form without manipulating Symfonys form component.

Pass/bind data objects to inner/embedded Symfony2 forms

i have the following form where i would like to pass some objects to the inner forms in order to populate them with data when being edited:
public function __construct( $em, $id )
{
$this->_em = $em;
}
public function buildForm( \Symfony\Component\Form\FormBuilderInterface $builder, array $options )
{
$builder->add( 'accessInfo', new AccessInfoType( $this->_em, $options[ 'entities' ][ 'user' ] ) , array(
'attr' => array( 'class' => 'input-medium' ),
'required' => false,
'label' => false
)
);
$builder->add( 'profileInfo', new ProfileInfoType( $this->_em, $options[ 'entities' ][ 'profile' ] ) , array(
'required' => false,
'label' => false
)
);
}
public function setDefaultOptions( \Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver )
{
$resolver->setDefaults( $this->getDefaultOptions( array() ) );
return $resolver->setDefaults( array( ) );
}
/**
* {#inheritDoc}
*/
public function getDefaultOptions( array $options )
{
$options = parent::getDefaultOptions( $options );
$options[ 'entities' ] = array();
return $options;
}
public function getName()
{
return 'UserType';
}
which i instantiate with the following code:
$form = $this->createForm( new UserType( $em ), null, array( 'entities' => array( 'user' => $userObj, 'profile' => $profileObj ) ) );
Once i get, via the constructor, the object containing the needed data does anyone know how could i bind that object to the form?
class ProfileInfoType extends AbstractType
{
private $_em;
public function __construct( $em, $dataObj )
{
$this->_em = $em;
$this->_dataObj = $dataObj;
}
Thanks in advanced!
I was having the same issue and fixed this with inherit_data
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'inherit_data' => true,
));
}
See also http://symfony.com/doc/current/cookbook/form/inherit_data_option.html
Inside your controller yo should get the request data
$request = $this->getRequest();
or request it through the method parameters
public function newAction(Request $request)
and then bind it to the form
$form->bind($request);
For further details have a look at http://symfony.com/doc/2.1/book/forms.html#handling-form-submissions
this works well add an attr for use the html attribute 'value' depends of the form type, maybe this can help you.
Twig
{{ form_label(blogpostform.title) }}
{{ form_widget(blogpostform.title, {'attr': {'value': titleView }}) }}
{{ form_errors(blogpostform.title) }}

Symfony2/ Use custom repository method in a formType

I am new with Symfony2, hopefully I am clear enough.
I have a repository:
class districtRepository extends EntityRepository
{
public function findAllFromCity($idCity)
{
return $this->createQueryBuilder('d')
->where('d.city = :city')
->setParameter('city', $idCity)
->orderBy('d.name', 'ASC');
->getQuery()
->getResult();
}
}
And a form type
class searchPropertyType extends AbstractType
{
public function getDefaultOptions(array $options)
{
// return array('validation_constraint' => $collectionConstraint
return array ('required'=>false, 'csrf_protection' => true);
}
public function buildForm(FormBuilder $builder, array $options)
{
$em = $this->getDoctrine()->getEntityManager();
$builder
->add('keywords')
->add('disctrict')
->add('price_min')
->add('price_max')
->add('type')
->add('date_from' , 'date', array('widget' => 'single_text'))
->add('date_to' , 'date', array('widget' => 'single_text'))
;
}
public function getName()
{
return 'searchProperty';
}
}
How do I simply use findAllFromCity() to get a list of option in ->add('disctrict') ??
I know the Query Builder solution, but it makes me repeating my code.
I've read about the service container solution. Is is applicabe in my case? Can you show me how or put me on good tracks??
Indeed, only way to access your 'findAllFromCity' method in the 'searchPropertyType' class is to inject the Doctrine registry.
In your form type class:
use Symfony\Bridge\Doctrine\RegistryInterface;
class searchPropertyType extends AbstractType
{
private $doctrine;
public function __construct(RegistryInterface $doctrine)
{
$this->doctrine = $doctrine;
}
In your services.xml file:
<service id="my_project.form.type.search_property" class="{mynamespace}\searchPropertyType" public="false">
<tag name="form.type" />
<argument type="service" id="doctrine" />
</service>
In order to use this this method, you'll have to use the 'choice' type with 'choices' or 'choice_list' option.
In your form type class:
public function buildForm(FormBuilder $builder, array $options)
{
$builder
// ...
->add('disctrict', 'choice', $this->getDistrictChoices($options['city_id']))
// ...
;
}
private function getDistrictChoices()
{
$choices = array();
$districts = $this->doctrine->getRepository('MyBundle:District')->findAllFromCity($cityId);
foreach ($dictricts as $dictrict) {
$choices[$district->getId()] = $district->getName();
}
return $choices;
}
Of course, this is an example and it needs to be adapted.
And remember: class name fisrt letters are always in upper case.
Thanks to Simon, I have updated as follow and it is now working!
searchController:
public function basicsearchAction(Request $request)
{
$form = $this->createForm(new searchPropertyType($this->getDoctrine()));
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
}
searchPropertyType
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('keywords')
->add('district', 'choice', array('choices'=>$this->getDistrictChoices(), 'multiple'=>true) )
->add('price_min')
->add('price_max')
->add('type', 'entity', array('class'=>'FlatShanghaidefaultBundle:propertytype',
'property'=>'name',
'multiple'=>true
))
->add('date_from' , 'date', array('widget' => 'single_text'))
->add('date_to' , 'date', array('widget' => 'single_text'))
;
}
private function getDistrictChoices()
{
$choices = array();
$districts = $this->doctrine->getRepository('FlatShanghaidefaultBundle:district')->findByDefaultCity();
foreach ($districts as $district) {
$choices[$district->getId()] = $district->getName();
}
return $choices;
}
service.yml
services:
search_property:
class: FlatShanghai\propertyBundle\Form\searchPropertyType
arguments: [doctrine]
I was also concerned about repeated code. Not only for my query builder, but also didn't want to write a custom choice mapping such as "getDistrictChoices". I chose to abstract my query inside my EntityRepository to make it available in my form type as well.
Here's what I did.
My form:
class UserEditType extends AbstractType
{
/**
* #var Session $session
*/
private $session;
public function __construct(Session $session){
$this->session = $session;
}
/**
* #param FormBuilderInterface $builder
* #param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('firstName')
->add('middleName')
->add('lastName')
->add('username')
->add('userStatus', EntityType::class, [
'class' => UserStatus::class,
'property' => 'status',
'query_builder' => function(UserStatusRepository $er) {
return $er->createQueryBuilder('s')
->orderBy('s.status');
},
])
->add('agency', EntityType::class, [
'class' => WorkflowGroup::class,
'property' => 'groupName',
'query_builder' => function(WorkflowGroupRepository $er) {
return $er->createSelectAllQB($this->session->get(AbstractController::SESSION_KEY_AGENCY_ID));
},
])
->add('phoneNumber')
->add('email', EmailType::class)
->add('activationDate', DateType::class, [
'widget' => 'single_text',
'format' => 'M/d/yyyy',
'attr' => [
'data-provide' => 'datepicker',
'data-date-format' => 'mm/dd/yyyy',
'data-date-show-on-focus' => 'false',
'data-date-auto-format' => 'true'
]
])
->add('expirationDate', DateTimeType::class, [ 'widget' => 'single_text', 'format' => 'yyyy-MM-dd HH:mm' ]);
;
}
...
}
My Repository:
class WorkflowGroupRepository extends EntityRepository
{
public function createSelectAllQB($agencyId)
{
return $this->createQueryBuilder('w')
->addOrderBy('w.groupName', 'ASC')
->andWhere('w.agencyId = :agencyId')
->setParameter('agencyId', $agencyId);
}
public function selectAll($agencyId)
{
return $this->createSelectAllQB($agencyId)->getQuery()->execute();
}
}

symfony2 chained selectors

I have three entities: Country, State and City with the following relationships:
When creating a City, I want two selectors, one for the Country and one for the State where the city belongs. These two selectors need to be chained so changing the Country will "filter" the States shown in the other selector.
I found a tutorial showing how to do this using Form Events but their example it's not quite my case. My entity City it's not directly related to the Country entity (they are indirectly related through State) so, when setting the country field in the City form (inside the class CityType), I'm forced to declare that field as 'property_path'=>false as you can see in the code below:
class CityType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('country', 'entity', array(
'class'=>'TestBundle:Country',
'property'=>'name',
'property_path'=>false //Country is not directly related to City
));
$builder->add('name');
$factory = $builder->getFormFactory();
$refreshStates = function ($form, $country) use ($factory)
{
$form->add($factory->createNamed('entity', 'state', null, array(
'class' => 'Test\TestBundle\Entity\State',
'property' => 'name',
'query_builder' => function (EntityRepository $repository) use ($country)
{
$qb = $repository->createQueryBuilder('state')
->innerJoin('state.country', 'country');
if($country instanceof Country) {
$qb->where('state.country = :country')
->setParameter('country', $country);
} elseif(is_numeric($country)) {
$qb->where('country.id = :country')
->setParameter('country', $country);
} else {
$qb->where('country.name = :country')
->setParameter('country', "Venezuela");;
}
return $qb;
}
)));
};
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (DataEvent $event) use ($refreshStates)
{
$form = $event->getForm();
$data = $event->getData();
if($data == null)
return;
if($data instanceof City){
if($data->getId()) { //An existing City
$refreshStates($form, $data->getState()->getCountry());
}else{ //A new City
$refreshStates($form, null);
}
}
});
$builder->addEventListener(FormEvents::PRE_BIND, function (DataEvent $event) use ($refreshStates)
{
$form = $event->getForm();
$data = $event->getData();
if(array_key_exists('country', $data)) {
$refreshStates($form, $data['country']);
}
});
}
public function getName()
{
return 'city';
}
public function getDefaultOptions(array $options)
{
return array('data_class' => 'Test\TestBundle\Entity\City');
}
}
The problem is that when I try to edit an existing City, the related Country is not selected by default in the form. If I remove the line 'property_path'=>false I get (not surprisingly) the error message:
Neither property "country" nor method "getCountry()" nor method "isCountry()" exists in class "Test\TestBundle\Entity\City"
Any ideas?
OK, I finally figured out how to do it properly:
namespace Test\TestBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\Event\DataEvent;
use Test\TestBundle\Entity\Country;
use Test\TestBundle\Entity\State;
use Test\TestBundle\Entity\City;
class CityType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('name');
$factory = $builder->getFormFactory();
$refreshStates = function ($form, $country) use ($factory) {
$form->add($factory->createNamed('entity','state', null, array(
'class' => 'Test\TestBundle\Entity\State',
'property' => 'name',
'empty_value' => '-- Select a state --',
'query_builder' => function (EntityRepository $repository) use ($country) {
$qb = $repository->createQueryBuilder('state')
->innerJoin('state.country', 'country');
if ($country instanceof Country) {
$qb->where('state.country = :country')
->setParameter('country', $country);
} elseif (is_numeric($country)) {
$qb->where('country.id = :country')
->setParameter('country', $country);
} else {
$qb->where('country.name = :country')
->setParameter('country', null);
}
return $qb;
})
));
};
$setCountry = function ($form, $country) use ($factory) {
$form->add($factory->createNamed('entity', 'country', null, array(
'class' => 'TestBundle:Country',
'property' => 'name',
'property_path' => false,
'empty_value' => '-- Select a country --',
'data' => $country,
)));
};
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (DataEvent $event) use ($refreshStates, $setCountry) {
$form = $event->getForm();
$data = $event->getData();
if ($data == null) {
return;
}
if ($data instanceof City) {
$country = ($data->getId()) ? $data->getState()->getCountry() : null ;
$refreshStates($form, $country);
$setCountry($form, $country);
}
});
$builder->addEventListener(FormEvents::PRE_BIND, function (DataEvent $event) use ($refreshStates) {
$form = $event->getForm();
$data = $event->getData();
if(array_key_exists('country', $data)) {
$refreshStates($form, $data['country']);
}
});
}
public function getName()
{
return 'city';
}
public function getDefaultOptions(array $options)
{
return array('data_class' => 'Test\TestBundle\Entity\City');
}
}
The jQuery AJAX selector
$(document).ready(function () {
$('#city_country').change(function(){
$('#city_state option:gt(0)').remove();
if($(this).val()){
$.ajax({
type: "GET",
data: "country_id=" + $(this).val(),
url: Routing.generate('state_list'),
success: function(data){
$('#city_state').append(data);
}
});
}
});
});
I hope this will be helpful to somebody else facing the same situation.
Since your link to this approach is down i decided to complement your excelent answer so anyone can use it:
In order to execute the following javascript command:
url: Routing.generate('state_list'),
You need to install FOSJsRoutingBundle that can be found in here.
ATENTION: in the read me section of the bundle there are instalation instructions but there is something missing. If you use the deps with this:
[FOSJsRoutingBundle]
git=git://github.com/FriendsOfSymfony/FOSJsRoutingBundle.git
target=/bundles/FOS/JsRoutingBundle
You must run the php bin/vendors update before the next steps.
I'm still trying to find out what route is needed in the routing.yml for this solution to work. As soon as i discover i will edit this answer.
You will need a dedicated FieldType for the chained selectbox. And also an xhr controller that can return child options based on passed parameter. Ofcourse property_path should be set to false.

Resources