2017-07-17 6 views
-1

Da ich alle meine Javascript und jQuery-Datei zusammengestellt habe, hat die Jquery Plugin-Sammlung für Symfony nicht funktioniert. Ich weiß nicht, warum, aber wenn ich auf die Schaltfläche Hinzufügen klicken, wird nichts passieren ...Jquery Collection Plugin für Symfony funktioniert nicht

Hier ist meine jQuery-Code:

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(); 
        } 
       }) 
      }) 
     } 
    }) 

Hier ist die Formularansicht: formView

Das ist, wie Ich erstelle meinen 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', 
         ),)); 

Wenn ich auf die Schaltfläche Hinzufügen (in blau) geklickt habe, passiert nichts. Wenn jemand eine Idee hat, wird es gut zu wissen sein. Vielen Dank im Voraus.

+0

Was möchten Sie? ein neues Feld hinzufügen, wenn Sie auf Ihre Schaltfläche klicken? –

+0

Ja, ich vermied es zu sagen, dass dies funktionierte, da ich alle meine JS-Datei zusammengestellt habe, hatte ich kein Problem vor ... –

+0

ok, also zuerst, ich weiß nicht, warum Sie alle JS-Code tat, dynamisch SF-Formular ist wie folgt: https://symfony.com/doc/current/form/dynamic_form_modification.html#dynamic-generation-for-submitted-forms zweite Sache, bearbeiten Sie Ihren Beitrag mit allen Elementen, die wir brauchen, um Ihnen zu helfen ... –

Antwort

0

Problem gelöst. Ich füge einfach hinzu, um eine my-selector-Klasse hinzuzufügen, die gelöscht wurde. Ich weiß nicht wie, aber alles funktioniert jetzt.

Verwandte Themen