如何在yii2中的模态窗口中重新加载pjax div

时间:2016-01-12 08:48:48

标签: yii2 bootstrap-modal pjax

我使用modal查看评论列表,模式有更新按钮和文本框。

当用户在文本框中输入一些文本并单击更新按钮时,我希望重新加载注释列表div,而不会重新加载整个页面或关闭或隐藏模式。

我已经读过了 How to update widget with pjax in modal window in yii2 阙。但仍然没有得到解决方案。

我的代码是

已注册的J和查看文件

$this->registerJs("
$(function() {
    $('#replayMeg').on('beforeSubmit', function(event, jqXHR, settings) {
        var comment = $('#".Html::getInputId($modelReply, 'hdr_comments')."').val();
        var ticketId = $model->hdt_id;

        $.ajax({
            url: '".Url::to(['helpdesk-replies/create'])."',
            type: 'post',
            data: { replyMsg : comment, ticketId : ticketId},
            beforeSend: function() {
                if($('#".Html::getInputId($modelReply, 'hdr_comments')."').val() == '')
                {
                    $('.field-helpdeskreplies-hdr_comments').addClass('form-group field-helpdeskreplies-hdr_comments required has-error');
                    $('.help-block').html('Reply cannot be blank.');
                    return false;
                }
            },
            success: function(data) {
                //$.pjax.reload({container:'#update_replyBox'});
            }
        });

        return false;
    })
});
");

<?php yii\widgets\Pjax::begin(['id' => 'update_replyBox']); ?>
<div class="modal-body">
<div class="box-tools pull-right">
               <?= $actionBtn; ?>
            </div>
</div>
<div class="panel panel-info">
          <div class="panel-heading colorchangeheader left-align">
            <i class="fa fa-users fa-fw"></i> <?= $model->getUserName($cData['hdr_replay_user_id']); ?> <span class="mobilebreakpoint"><i class="fa fa-clock-o fa-fw"></i><?= Yii::$app->formatter->asDate($cData['created_at']); ?> @ <?= Yii::$app->formatter->asTime($cData['created_at']); ?></span>
          </div>
          <div id="rp8" class="panel-body">
           <?= $cData['hdr_comments'] ?>
          </div>
    </div>

<?php $form = ActiveForm::begin(['id' => 'replayMeg']); ?>
        <div class="box-body">
            <div class='row'>
                <div class='col-sm-12'>
                    <?= 
                        $form->field($modelReply, 'hdr_comments')->widget(RemainingCharacters::className(), [
                            'type' => RemainingCharacters::INPUT_TEXTAREA,
                            'name' => 'message_body',
                            'id' => 'message_body-textarea',
                            'text' => Yii::t('app', '{n} Characters Remaining'),
                            'label' => [
                                'tag' => 'p',
                                'id' => 'my-counter',
                                'class' => 'counter text-aqua',
                                'invalidClass' => 'error'
                            ],
                            'options' => [
                                'rows' => '3',
                                'class' => 'form-control replyTextArea',
                                'maxlength' => 200,
                                'placeholder' => Yii::t('app', 'Write something'),
                            ]
                        ]);
                    ?>
                </div>
            </div>
        <!--/div>
        <div class="box-footer"-->
            <?= Html::button('<i class="fa fa-reply"></i> '.Yii::t('comm', 'Reply'), ['class' => 'btn btn-info btn-create submit', 'type' => 'submit']) ?>
        </div>
        <?php ActiveForm::end(); ?>

    <?php yii\widgets\Pjax::end() ?>

enter image description here

1 个答案:

答案 0 :(得分:3)

请尝试在模态中设置backdrop false

'clientOptions' => ['backdrop' => false]

在您的有效表单中设置data-pjax为真

<?php $form = ActiveForm::begin(['options' => ['data-pjax' => true ]]); ?>

有关详细信息http://www.yiiframework.com/wiki/772/pjax-on-activeform-and-gridview-yii2/

有关模态Refer

的更多选项