Validation for DateTime Widget

Hi everybody.

Thanks for reading this stuff.

I am using dosamigos DateTimePicker component in my app and almost all things are fine. The only issue that I can not figure out is how to enable/make client validation for this type of fiedl.

[b]

The widget code:[/b]


echo DateTimePicker::widget([

    'model' => $model,

    'attribute' => 'date',

    'size' => 'ms',

    'clientOptions' => [

        'autoclose' => true,

        'startView' => 3,

        'minView' => 3,

        'maxView' => 4,    

        'format' => 'yyyy-mm-dd'        

    ],

]);

The Model Code - rules() function


public function rules()

    {

        return [

            [['id', 'date'], 'required'],

            [['date'], 'date', 'format' => 'yyyy-mm-dd']

        ];

    }




The logic works fine, so the model is not submitted due to false validation, but I really want to show user standard ‘has-error’ class when he forgets to pick the date from the field.

Please do not hesistate any questions or ask for other snippets.

Many thanks in advance!

[color="#006400"]/* Moved from "General Discussions" to "Extensions" */[/color]

The problem is that you use the widget directly, thus not displaying the element where the errors are displayed by yii. The proper way to do it is:




echo $form->field($model, 'date')->widget(DateTimePickerWidget::class, [ ... ]);