I am using SonataAdminBundle version 2.0 with Symfony2 version 2.0.11
My entities have several OneToMany relationships and I want to make the selection easier by using the Chosen JQuery plugin.
Here is the Entity definition:
class Merchant
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string $name
*
* @ORM\Column(name="name", type="string", length=255)
* @Gedmo\Translatable
*/
private $name;
/**
* @ORM\ManyToMany(targetEntity="Category", inversedBy="merchants")
*/
public $categories;
/**
* @ORM\ManyToOne(targetEntity="Category", inversedBy="merchants")
*/
protected $primaryCategory;
...
}
Here is a sample Admin code:
$formMapper
->add('name')
->add('primaryCategory', 'sonata_type_model', array('attr' => array('class' => 'chzn-select')))
->add('categories', 'sonata_type_model', array('expanded' => false, 'multiple' => true, 'attr' => array('class' => 'chzn-select')))
I have confirmed that chosen.css and chosen.js are loaded in the page. But I don't see the corresponding sprites being loaded. Neither do I see any "Chosen" magic.
Am I missing something here? How can I correctly integrate Chosen with SonataAdmin?
It worked, I had forgotten to initialize the select options with chosen on $().ready()
Here is the code:
$().ready(function () {
$('select.chzn-select').chosen();
...
...
It comes neatly now.