-1
私はJavascriptとjQueryファイルをまとめましたので、SymfonyのJqueryプラグインコレクションは機能しませんでした。ここでsymfonyのJqueryコレクションプラグインが動作しません
は私のjQueryのコードです...私はなぜ知らないが、私は追加ボタンをクリックすると、何も起こりません:
var indexAdd = 0
var collectionToAdd ='';
jQuery('.my-selector').collection({
allow_up: false,
allow_add: true,
allow_down: false,
after_remove: function(collection, element) {
indexAdd--;
var count = 0;
jQuery(collection).children().each(function(){
if(jQuery(this).is('div')){
count++;
}
})
if(count > 1){
jQuery(element).find("a.collection-add.collection-action").eq(indexAdd-1).parent().show();
}
if(count == 0){
jQuery(collection).find('a.collection-action.collection-rescue-add').css('display','unset');
}
},
after_add: function(collection, element) {
jQuery(element).css('margin-top','50px');
indexAdd++;
collectionToAdd = '';
collectionToAdd = collection;
jQuery('#modalCollection .modal-body .col-6').empty()
var nomCollection = jQuery(jQuery(collection).parent()).parent().find('label').eq(0).text()
if(jQuery('#modalCollection .modal-body .col-6 h1').length == 0){
jQuery('#modalCollection .modal-body .col-6').append('<h1>'+nomCollection+'</h1>')
}
jQuery('#modalCollection .modal-body .col-6').append('<div class="detach"></div>')
jQuery('#modalCollection').modal('show');
jQuery(jQuery(element).detach()).appendTo('#modalCollection .modal-body .detach')
jQuery(element).parent().children("div").each(function(){
jQuery(this).children("label").css('display','none')
})
jQuery(element).find('label').each(function(event){
if(jQuery(this).text().indexOf('label') > 0){
jQuery(this).hide();
}
})
newCollection = jQuery(element).parent().find("div:last").parent()
jQuery(newCollection).find("div").wrap('<td></td>')
jQuery(newCollection).find("div").each(function(){
jQuery(this).find("td").wrapAll(('<tr></tr>'))
if(jQuery(this).find("label")){
label = jQuery(this).find("label").attr("for")
if(typeof label !== 'undefined'){
label = (label.substring(0, String(label).indexOf('-'))).substring(label.lastIndexOf("_")+1)
jQuery(this).find("label").html(label)
}
}
})
jQuery(element).find('td').each(function(){
jQuery(this).find('div').attr("class","md-form")
jQuery(this).find('div').each(function(){
if(jQuery(this).find('input').attr('type') == 'file'){
jQuery(this).find('label').hide();
}
})
})
}
})
ここでは、フォームビューである:formView
方法ですこと私は自分のコレクションタイプを作成します:
$builder->add($key, CollectionType::class, array(
'entry_type' => DynamicFormType::class,
'entry_options' => array('data' => $arrayOfFieldType),
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'attr' => array(
'class' => 'my-selector',
),));
私は追加ボタン(青色)をクリックしても何も起こりません。 誰かがアイデアを持っているなら、知っておくといいでしょう。 ありがとうございます。
何が欲しいですか?ボタンをクリックしたときに新しいフィールドを追加しますか? –
はい、私はJSファイルのすべてをまとめて以来、これはうまくいったとは言いません... –
OK、まず、私はなぜあなたはすべてのJSコード、動的SFフォームは次のようなものです:https://symfony.com/doc/current/form/dynamic_form_modification.html#dynamic-generation-for-submitted-forms もう一つは、私たちがあなたを助けるために必要なすべての要素であなたの投稿を編集する... –