Browse Source

ignore invalid date format and just display value as is

fixes #5155
tags/2.0.0-rc
Carsten Brandt 10 years ago
parent
commit
68714cc805
  1. 8
      extensions/jui/DatePicker.php

8
extensions/jui/DatePicker.php

@ -8,6 +8,7 @@
namespace yii\jui;
use Yii;
use yii\base\InvalidParamException;
use yii\helpers\FormatConverter;
use yii\helpers\Html;
use yii\helpers\Json;
@ -154,7 +155,12 @@ class DatePicker extends InputWidget
$value = $this->value;
}
if ($value !== null) {
$value = Yii::$app->formatter->asDate($value, $this->dateFormat);
// format value according to dateFormat
try {
$value = Yii::$app->formatter->asDate($value, $this->dateFormat);
} catch(InvalidParamException $e) {
// ignore exception and keep original value if it is not a valid date
}
}
$options = $this->options;
$options['value'] = $value;

Loading…
Cancel
Save