使用Select2的Symfony2 GenemuFormBundle集合

时间:2013-02-11 20:54:43

标签: symfony symfony-2.1 symfony-forms

我正在尝试将此捆绑包作为一个集合(多对多关系)。 我以这种方式设置了一组数据:

->add('subCategory', 'genemu_jqueryselect2_entity', array(
        'class' => 'Coffee\BusinessBundle\Entity\SubCategories',
        'property' => 'subCategory',
        'label' => 'Sotto Categorie',
        'multiple' => true,
        'configs' => array(
            'placeholder' => 'Seleziona almeno una sotto categoria',
        )
    ))
****

in anagraficType:

 ->add('subCategories', 'collection', array('type' => new SubCategoriesType(), 
                'allow_add' => true,
                'allow_delete' => true,
                'prototype' => true,
                'prototype_name' => '__categ__',
                'by_reference' => false
            ))

在我的模板中:

var collectionHolder3 = $('ul.categories');
var $addTagLink3 = $('<a href="#" class="add_refer_link">Aggiungi</a>');
var $newLinkLi3 = $('<li></li>').append($addTagLink3);
collectionHolder3.append($newLinkLi3);
function triggerJavascript(id)
{
    $field = $('#' + id);
    {{ form_javascript(form3.subCategories.vars.prototype, true) }}
}
function addCatForm() {
    var prototype = collectionHolder3.attr('data-prototype');
    var newIndex = collectionHolder3.find('option').length;
    var newForm = prototype.replace(/__categ__/g, newIndex);
    var $newFormLi = $('<li></li>').append(newForm);
    $newLinkLi3.before($newFormLi);

    var id = '{{ form3.subCategories.vars.id }}_' + id;
    triggerJavascript(id);
}
addCatForm(collectionHolder3, $newLinkLi3);

//..
<ul class="categories" data-prototype="{{ form_widget(form3.subCategories.get('prototype')) | e }}">
</ul>

为什么我会收到此错误?

An exception has been thrown during the rendering of a template 
("Unable to render the form as none of the following blocks exist:
"_my_businessbundle_anagraficatype_subCategories_entry_javascript_prototype",
"subCategories_javascript_prototype", "form_javascript_prototype".") in..

我的配置错误在哪里?

1 个答案:

答案 0 :(得分:1)

这不能解决问题,但问题的答案是:

我联系了捆绑包的创建者并且是捆绑包中的一个错误,不幸的是这个捆绑包有几个错误,因此解决方案是删除它并手动使用Select2。