kartik-v / yii2-widgets

Collection of useful widgets for Yii Framework 2.0
http://demos.krajee.com/widgets
Other
558 stars 177 forks source link

DatePicker client validation #75

Closed alexweb-zz closed 10 years ago

alexweb-zz commented 10 years ago

I'm using DatePicker this way:

    <div class="form-group field-code-start_date required">
        <?= Html::activeLabel($model, 'start_date', ['class'=>'control-label']) ?>
        <?php
        $model->start_date = ($model->isNewRecord)
            ? null
            : date('Y-m-d',$model->start_date);
        ?>
        <?= DatePicker::widget([
            'model' => $model,
            'attribute' => 'start_date',
            'pluginOptions' => [
                'format' => 'yyyy-M-dd',
                'todayHighlight' => true,
                'clearButton' => false,
            ]
        ]);?>
        <?= Html::error($model, 'start_date') ?>
    </div>

And I have 'required' rule for 'start_date'. When I click Submit button, error doesn't appear (client validation). Is it supported or I need to use ajax validation?

alexweb-zz commented 10 years ago

Ok. Found why it's not working. The "form" parameter should be specified:

    <?php
    $model->end_date = ($model->isNewRecord)
        ? null
        : date(Yii::$app->params['dateFormat'], $model->end_date);
    ?>
    <?= DatePicker::widget([
        'model' => $model,
        'form' => $form,
        'attribute' => 'end_date',
        'pluginOptions' => [
            'format' => 'yyyy-mm-dd',
            'todayHighlight' => true,
            'clearButton' => false,
        ]
    ]);?>