I am trying to use the yii2/jui/DatePicker and just can’t get it to work. I have thre of them on a view, attached to a $model via attributes. If I don’t enter anything it is fine, click on a date, validation fails with “Invalid Date Format”
In the model
/*
* @property integer $birth_date
* @property integer $aniversary_date
* @property integer $hire_date
*/
public function rules() {
return [
...
[['birth_date', 'aniversary_date', 'hire_date'], 'default', 'value' => null],
...
[['aniversary_date'], 'date', 'timestampAttribute' => 'aniversary_date', 'skipOnEmpty' => true],
[['hire_date'], 'date', 'timestampAttribute' => 'hire_date', 'skipOnEmpty' => true],
//[['birth_date', 'aniversary_date', 'hire_date'], 'safe'],
...
In the View _form.php
use yii\bootstrap\ActiveForm;
use yii\jui\DatePicker;
<?php
$form = ActiveForm::begin([
'layout' => 'horizontal',
'fieldConfig' => [
'horizontalCssClasses' => [
'label' => 'col-sm-3',
'offset' => 'col-sm-offset-2',
'wrapper' => 'col-sm-8',
],
],
]);
<?php
echo $form->field($model, 'birth_date')->widget(DatePicker::className(), [
'options' => ['class' => 'form-control'],
'dateFormat' => 'short,
'clientOptions' => [
'showOn' => "button",
'buttonImage' => Url::to('@web/images/calendar.gif'),
'buttonImageOnly' => true,
'buttonText' => "Select date"
],
]);
?>
<?php
echo $form->field($model, 'aniversary_date')->widget(DatePicker::className(), [
'options' => ['class' => 'form-control'],
'dateFormat' => 'short',
'clientOptions' => [
'showOn' => "button",
'buttonImage' => Url::to('@web/images/calendar.gif'),
'buttonImageOnly' => true,
'buttonText' => "Select date"
],
]);
?>
<?php
echo $form->field($model, 'hire_date')->widget(DatePicker::className(), [
'options' => ['class' => 'form-control'],
'dateFormat' => 'short',
'clientOptions' => [
'showOn' => "button",
'buttonImage' => Url::to('@web/images/calendar.gif'),
'buttonImageOnly' => true,
'buttonText' => "Select date"
],
]);
?>
</div>
<?php ActiveForm::end(); ?>
Thank in advance for any help.
P.S. Why is the ‘short’ format ‘d/m/y’ and not ‘m/d/y’, since the default language of Yii is en-US?