2017-07-17 15 views
-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

那怎麼我創建我的CollectionType:

$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', 
         ),)); 

當我點擊添加按鈕(藍色)沒有任何事情發生。 如果有人有一個想法,將很高興知道。 在此先感謝。

+0

你想要什麼?當你點擊你的按鈕時添加一個新的字段? –

+0

是的,我ommited說,這是因爲我把所有的JS文件放在一起,我以前沒有問題... –

+0

好吧,所以首先,我不知道你爲什麼做了所有的JS代碼,動態SF的形式是這樣的:https://symfony.com/doc/current/form/dynamic_form_modification.html#dynamic-generation-for-submitted-forms 第二件事,編輯您的文章與我們需要幫助你的所有元素... –

回答

0

問題解決了。我只是添加添加一個我刪除的我的選擇器類,我不知道如何,但一切正在工作。