我有同样的问题。
我用GenumFormBundle修复了它。
与作曲家一样安装它:composer.json
{
"require": {
"_some_packages": "...",
"genemu/form-bundle": "2.1.*" => for Symfony 2.1 and 2.2
"genemu/form-bundle": "2.2.*" => for Symfony 2.3
}
}
不要忘记将包添加到AppKernel.php和运行的assetic命令:
$ php app/console assets:install web/
之后,您可以使用它进入Admin类:
protected function configureFormFields(FormMapper $formMapper)
{
// ...
$formMapper
->with('General')
->add('sample_choice', 'genemu_jqueryautocompleter_choice', array(
'choices' => array(
'Choice 1' => 'Choice 1',
'Choice 2' => 'Choice 2',
'n.a.' => 'Not available'
)))
请参阅自动填充字段类型可用的文档。 你也可以选择实体。但请注意,只有数据库条目的id才会在表单中返回,而不是值!
使用过滤器作案:
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
// ...
->add('customer', null, array(), 'genemu_jqueryautocompleter_entity')
// ...
注意:你必须将下面一行添加到您的布局:
{{ form_stylesheet(form) }}
and
{{ form_javascript(form) }}
感谢您的回答!我试图使用genemuFormBundle,但它似乎不起作用...有一个针对奏鸣曲和genemu的特定模板配置? –
嗯,我不确定,但默认情况下,如果genemu包加载正确,该选项应该可用。 注意:它在ajax弹出窗口中不起作用。似乎有一个问题,当加载必要的头文件或与其他jquery库冲突。 – sensi
看到我上面的更新。您必须在主布局的twig文件中添加{{form_stylesheet(form)}}和 {{form_javascript(form)}}。 – sensi