-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Broken date after widget formats the date after form submission #91
Comments
That's definitely not desired behavior. Any idea on how to fix it? |
Well in my case I did a workaround without having to modify the widget's code. Basically I'm re-converting the date to But I think it is not the best solution. The solution I think is best, and should be adopted is to actually remove the part with the formatting of the value from inside the widget. I mean:
And if you look at Yii 1's DatePicker, you can specify a date format (for the javascript option), but the widget never formats the value to that format, it expects the value to be already formatted like that: https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/jui/CJuiDatePicker.php So if we remove the formatting from the widget:
Of course some of the conversions could be inside the model's methods such as |
What steps will reproduce the problem?
You create a form and you set the date format to
'dateFormat' => 'php:d/m/Y',
.Then you click the input and select 1 august 2020, and you get 01/08/2020 with the format specified, everything good.
The problem is if you then submit the form and stay on the same page (ej: some form validation fails), the widget will get
01/08/2020
value from the form and then re-format it, as it is here:https://github.com/yiisoft/yii2-jui/blob/master/src/DatePicker.php#L179
And you end up with this date in the input:
08/01/2020
.My feedback:
It looks like I have to manually reparse the date value to a different format, eg:
Y-m-d
, before rendering the datepicker after the model has been filled with post data.What's expected?
To keep
01/08/2020
.What do you get instead?
Re-formatted date
08/01/2020
.Additional info
The text was updated successfully, but these errors were encountered: