E
E
EVOSandru62015-07-23 14:40:42
Yii
EVOSandru6, 2015-07-23 14:40:42

Why in Yii enableAjaxValidation can block button click?

Good afternoon,
Logs do not swear at anything, strangeness ..
There is a Cars model :

public function rules()
  {
    return array
        (
      array(['category_id','name'], 'required'),
      array('category_id, sys_date, sys_date_update, sys_user, exist, order_sort', 'numerical', 'integerOnly'=>true),
      array('name, name_en, name_kz, name_alias, meta_d, meta_k', 'length', 'max'=>255),
      array('id, name, name_en, name_kz, category_id, sys_date, sys_date_update, sys_user, exist', 'safe', 'on'=>'search'),
    );
  }

All items are strictly observed and filled in the form:
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
  'id'=>'cars-form',
    'enableAjaxValidation' => true,
    'enableClientValidation'=>true,
    'clientOptions'=>
    [
        'validateOnSubmit'=>true,
    ],
    'htmlOptions' =>
    [
        'enctype' => 'multipart/form-data'
    ])); ?>

    <p class="note">Поля со <span class="required">*</span> обязательны.</p>

    <?php echo $form->errorSummary($model);?>


    <ul class="nav nav-tabs nav-catalog">
        <li class="active"><a data-toggle="tab" href="#panel1">RU</a></li>
        <li><a data-toggle="tab" href="#panel2">kz</a></li>
        <li><a data-toggle="tab" href="#panel3">en</a></li>
    </ul>

    <div class="tab-content">
        <div id="panel1" class="tab-pane fade in active">
            <table class="table">
                <tr>
                    <td>
                        <?php echo $form->labelEx($model,'name'); ?>
                    </td>
                    <td>
                        <?php echo $form->textField($model,'name',['size'=>60,'maxlength'=>255, 'placeholder'=>'1:43 МАЗ-5432']); ?>
                        <?php echo $form->error($model,'name'); ?>
                    </td>
                </tr>
                <tr>
                    <td>
                        <?php echo $form->labelEx($model,'name_alias'); ?>
                    </td>
                    <td>
                        <?php echo $form->textField($model,'name_alias',['size'=>60,'maxlength'=>255,'placeholder'=>'seo название']); ?>
                        <?php echo $form->error($model,'name_alias'); ?>
                    </td>
                </tr>
            </table>
        </div>

        <div id="panel2" class="tab-pane fade">
            <table class="table">
                <tr>
                    <td>
                        <?php echo $form->labelEx($model,'name_kz'); ?>
                    </td>
                    <td>
                        <?php echo $form->textField($model,'name_kz',['size'=>60,'maxlength'=>255,'placeholder'=>'kz название']); ?>
                        <?php echo $form->error($model,'name_kz'); ?>
                    </td>
                </tr>
            </table>
        </div>

        <div id="panel3" class="tab-pane fade">
            <table class="table">
                <tr>
                    <td>
                        <?php echo $form->labelEx($model,'name_en'); ?>
                    </td>
                    <td>
                        <?php echo $form->textField($model,'name_en',['size'=>60,'maxlength'=>255,'placeholder'=>'en название']); ?>
                        <?php echo $form->error($model,'name_en'); ?>
                    </td>
                </tr>
            </table>
        </div>
    </div>

    <table class = "table crudTable">
        <tr>
            <td>
                <?php echo $form->labelEx($model,'category_id'); ?>
            </td>
            <td>
                <?php// echo $form->dropDownList($model,'category_id', CHtml::listData($categories, 'id', 'name')); ?>

                <select name="Cars[category_id]" id="Cars_category_id">

                    <?php if(!empty($category)):?>
                        <option value="<?=$category->id;?>">
                            <?=$category->name;?>
                        </option>
                    <?endif;?>

                    <option value="<?=$root->id ?>"><?=$root->name;?></option>
                    <? if (!empty($categories)) : ?>
                        <? foreach ($categories as $item) : ?>
                            <option value="<?=$item->id;?>"
                                <?=!empty($_POST['category_id']) && $_POST['category_id']== $item->id || $category_id == $item->id? 'selected="selected"' : ''?>>
                                <?=str_repeat('_ _ ', $item->level), $item->name;?>
                            </option>
                        <? endforeach; ?>
                    <? endif;?>
                </select>

                <?php echo $form->error($model,'category_id'); ?>
            </td>
        </tr>

        <tr>
            <td>
                <?php echo $form->labelEx($model,'meta_d'); ?>
            </td>
            <td>
                <?php echo $form->textField($model,'meta_d',['size'=>60,'maxlength'=>255,'placeholder'=>'seo описание']); ?>
                <?php echo $form->error($model,'meta_d'); ?>
            </td>
        </tr>
        <tr>
            <td>
                <?php echo $form->labelEx($model,'meta_k'); ?>
            </td>
            <td>
                <?php echo $form->textField($model,'meta_k',['size'=>60,'maxlength'=>255,'placeholder'=>'seo ключевые слова']); ?>
                <?php echo $form->error($model,'meta_k'); ?>
            </td>
        </tr>
        <tr>
            <td>
                <?php echo $form->labelEx($model,'order_sort'); ?>
            </td>
            <td>
                <?php echo $form->numberField($model,'order_sort',['placeholder'=>'0']); ?>
                <?php echo $form->error($model,'order_sort'); ?>
            </td>
        </tr>
        <tr>
            <td>
                <?php echo $form->labelEx($model,'exist'); ?>
            </td>
            <td>
                <?php echo $form->checkBox($model,'exist'); ?>
                <?php echo $form->error($model,'exist'); ?>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <div class="row buttons">
                    <?php echo CHtml::submitButton($model->isNewRecord ? 'Создать' : 'Обновить',['class'=>'btn btn-primary']); ?>
                </div>
            </td>
        </tr>
    </table>
<?php $this->endWidget(); ?>

</div><!-- form -->

But for some reason, when the button is clicked, the form is not sent ( I get into only if set: in the form. But this does not quite suit me.
In the controller, the performAjaxValidation method is available:if(isset($_POST['Cars']))
'enableAjaxValidation' => false,

public function performAjaxValidation($model)
  {
    if(isset($_POST['ajax']) && $_POST['ajax']==='cars-form')
    {
      echo CActiveForm::validate($model);
      Yii::app()->end();
    }
  }

What could be wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question