yii2mod / yii2-comments

Comments module for Yii2
MIT License
158 stars 63 forks source link

Reinitialize the javascript methods #98

Open buttflattery opened 4 years ago

buttflattery commented 4 years ago

I am using the comments widget with yii2-scrollpager where i am loading the comments using the load more button, the problem is that the delete,reply cancel-reply buttons that call the javascript methods defined in the init() method of the js/comments.js are not binded with the newer elements is there any option to initialize them? as i cant find any

what i am doing is below

i have a view where i am calling a ListView with yii-scrollpager enabled and the view used for the ListView is _latest-bongy which has the yii2-comments widget see below

<?php
    Pjax::begin([
        'options' => [
            'id' => 'bongy',
        ],
        'enablePushState' => false,
    ]);
    echo ListView::widget([
        'dataProvider' => $bongyProvider,
        'itemView' => '_latest-bongy',
        'emptyText' => Yii::t('app', 'No bongy found'),
        'viewParams' => [
            'feelings' => $feelings,
            'comments'=>true
        ],
        'itemOptions' => [
            'class' => 'tweet-wrap',
        ],
        'options' => [
            'id' => 'list-wrapper',
        ],
        'pager' => [
            'class' => ScrollPager::class,
            'container' => '#list-wrapper',
            // 'negativeMargin' => 200,
            'item' => '.tweet-wrap',
            'paginationSelector' => '#list-wrapper>ul.pagination',
            'next' => '#list-wrapper>ul.pagination li.next a',
            'historyPrev' => '#list-wrapper>ul.pagination li.prev>a',
            'noneLeftText' => Yii::t('app', 'No more Bongies to display.'),
            'noneLeftTemplate' => '<div class="no-more"><span>{text}</span></div>',
            'triggerText' => Yii::t('app', 'Load More Bongies'),
            'triggerTemplate' => '<div class="load-more"><a href="javascript:void(0)"><i class="icon-spinner"></i>&nbsp;{text}</a></div>',
            'enabledExtensions' => [
                \kop\y2sp\ScrollPager::EXTENSION_TRIGGER,
                \kop\y2sp\ScrollPager::EXTENSION_SPINNER,
                \kop\y2sp\ScrollPager::EXTENSION_NONE_LEFT,
                \kop\y2sp\ScrollPager::EXTENSION_PAGING,
            ],
        ],
    ]);
    Pjax::end();
?>

_latest-bongy.php

i am only including the widget part from the view as the rest of the html is not relevant

echo Comment::widget(
              [
                  'model' => $model,
                  'maxLevel' => 3,
                  'formId' => "comment-form{$model->id}",
                  'pjaxContainerId' => "unique-pjax-container-{$model->id}",
                  'commentView' => '@app/views/user/comments/comment',
                  'dataProviderConfig' => [
                      'pagination' => [
                          'pageSize' => 3,
                          'pageParam' => 'comment-page',
                          'pageSizeParam' => 'comment-page-size',
                      ],
                  ],
                  'listViewConfig' => [
                      'emptyText' => Yii::t('app', 'No comments found.'),

                  ],
              ]
          );
ahmadfadlydziljalal commented 1 year ago

Hi, Have you managed to solve the problem above?

If yes, please share the information

sardjn commented 6 months ago

Please share the solution, if you managed to find it yet. Thanks