yii2两个活动表单需要第二次点击提交

时间:2018-05-12 11:59:53

标签: php forms yii2 active-form

我在视图中有两个activeform,其中一个使用pjax。并且他们都需要第二次点击提交。我不知道我做错了什么。我在互联网上搜索此问题,但遇到其他二次点击的情况

<?php Pjax::begin(['id' => 'workers', "timeout" => 50000], ["options" => ["timeout" => 5000]]);?> 
<?php
echo $this->render('_show', [
    "model" => $searchModel,
    "filials" => $filials,
    "workers" => $workers,
    "posts" => $posts,
]); 
echo $this->render('_handle_form');
?>


<div class="row js-loader">
<div class="col-lg-12 col-md-12">
    <div class="table-responsive">

    <?=GridView::widget([
        'dataProvider' => $dataProvider,
        'emptyText'    => 'Нет результатов',
        'tableOptions' => ['class' => 'table table-hover table-claim table-claimadm', 'style' => 'font-weight:600;'],
        'rowOptions' => ['class'=>'row-without-border row-open'],
        'layout' => "{items}{pager}",
        'columns' => [
            [
                ...            
        ]
    ]);?>

    </div>
</div>
</div>
<?php Pjax::end();?>
<script>
    window.onload = function () {
       $(document).on('pjax:send', function (event) {
        tbody = $('#' + event.target.id).find(".js-loader");
        if (tbody.length != 0) {
            tbody_height = tbody.height();
            tbody.html('<div class="block-loader" style="width:100%"></div>');
        }
    });
        $('#submit_with_answer').click(function() {
            if ($.trim($('#text-claim').val()).length > 0)
            {
                $('#complaint_feedback').submit();
            }
            else
            {
                $('#textarea-group').addClass('has-error');
                $('#answer_error').html('Заполните поле «Добавить текст ответа»');
            }
        });
    };

</script>

“_show”视图是:

<?php $form = ActiveForm::begin([
    'id' => 'complaints',
    'action' => Url::to(['complaints/show']),
    'method' => 'GET',
    'options' => 
        [
            'class' => 'form-respons form-claimadm',
            'data-pjax' => 1,
        ],
]);

   active fields....

    <div class="form-btns col-md-2 col-sm-6 col-xs-12">
        <?= Html::submitButton('Применить', ['class' => 'btn btn-primary','style'=>"float:right;"]) ?>
    </div>
</div>
<?php ActiveForm::end(); ?>

和_handle_form是:

<?php
use yii\widgets\ActiveForm;
use yii\helpers\Url;
?>

<?php
$form = ActiveForm::begin([
        'id' => 'complaint_feedback',
        'action' => Url::to(['complaints/handle-complaint']),
        'method' => 'POST',
        'options' => ['class' => 'form-respons form-claim-feedback','style'=>'display:none;'],
    ]);
?>
<div id="textarea-group" class="form-group">                                    
    <label for="text-claim" class="hidden-xs">Добавить текст ответа</label>
    <textarea class="form-control" id="text-claim" rows="3" name="complaint_answer" placeholder="Добавить текст ответа"></textarea>
    <div id="answer_error" class="help-block"></div>
    <input id="complaint_id" name="complaint_id" type="hidden" value="">
</div>  
<div class="clearfix form-btns">
    <button type="button" onclick="$('#complaint_feedback').submit();" class="btn btn-link">Обработать без ответа</button>
    <button id="submit_with_answer" type="button" class="btn btn-primary">Отправить</button>
</div>
<?php ActiveForm::end(); ?>
<a id="hide_handle_form" style="display: none;" onclick="$('#complaint_feedback').hide(); $('.handle_button').removeClass('disabled'); $(this).hide();$('tr[data-key='+$('#complaint_id').val()+']').removeClass('row-open');" class="btn btn-link btn-show-hide">Свернуть
</a>

如果我用pjax评论行,一切正常。我该如何解决这个问题?

0 个答案:

没有答案