Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatePicker transforms some invalid user input into invalid dates #28

Open
PowerGamer1 opened this issue Oct 17, 2015 · 0 comments
Open
Labels

Comments

@PowerGamer1
Copy link

In some cases (see example below) DatePicker transforms invalid user input into invalid date. Instead exact invalid user input must remain in the field.

Example:
Yii::$app->formatter->dateFormat is set to 'php:Y-m-d'
Date validator is set as:
['someDate', 'date']
DatePicker is rendered as:
<?= $form->field($model, 'someDate')->widget(DatePicker::className()) ?>

When user enters value '1234567' into DatePicker input field and submits the form that input field incorrectly displays '1970-01-15' instead of original user input '1234567'. This happens because the following code tries to format value '1234567' using Yii::$app->formatter->asDate() which in turn tries to parse its first argument as UNIX timestamp value:

    protected function renderWidget()
    {
        // ..........
        if ($value !== null && $value !== '') {
            // 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
            }
        }

Don't know how to work around that problem and I think to fix it a significant redesign of DatePicker will be needed.

@samdark samdark added the type:bug Bug label Oct 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants