Yii2 kartik typeahead not working with wbraganca dynamic form


(EdenRamoneda) #1
<?= $form->field($item, "[{$index}]code")->widget(Typeahead::classname(), [
          'options' => ['placeholder' => 'Choose from existing or enter new code'],
          'pluginOptions' => ['highlight' => true, 'minLength' => 3],
          'scrollable' => true,
          'dataset' => [
                            [
                                'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('value')",
                                'display' => 'value',
                                'prefetch' => Url::to(['app/app-codes']),
                                'remote' => [
                                      'url' => Url::to(['app/code']) . '?q=%QUERY',
                                      'wildcard' => '%QUERY'
                                 ],
                                 'limit' => 100,
                            ]
                       ]
          ]); ?>

my jquery

<?php

$js = '

jQuery(".dynamicform_wrapper").on("afterInsert", function(e, item) {

    jQuery(".dynamicform_wrapper .panel-title-address").each(function(index) {

        jQuery(this).html("Items: " + (index + 1))

        jQuery("#item" +(index + 1) + "-code").parent().typeahead({highlight:true, minLength:3});
    });

});


jQuery(".dynamicform_wrapper").on("afterDelete", function(e) {

    jQuery(".dynamicform_wrapper .panel-title-address").each(function(index) {

        jQuery(this).html("Items: " + (index + 1))

        jQuery("#item" +(index + 1) + "-code").parent().typeahead({highlight:true, minLength:3});

    });

});

';


$this->registerJs($js);