jQWidgets Forums
jQuery UI Widgets › Forums › Editors › DateTimeInput › Date Format From Null Value not being Set
Tagged: date format
This topic contains 5 replies, has 2 voices, and was last updated by bmg125 10 years, 4 months ago.
-
Author
-
I am having an issue where the date is not properly formatted when going from a null value to a selected date. Instead of setting the value to the correct formatting it is using the default format. I am using the JQX Widgets with KnockoutJS Bindings which seems to be part of the problem because when I use the DateTimeInput widget as in this jsfiddle: http://jsfiddle.net/jqwidgets/TeQMx/ it is working correctly.
Here is an example that shows the problem. The second widget that starts with a null date isn’t properly formatted when you select a date for it. Any ideas how to get the widget to correctly format in this case?
Thanks!
<html>
<head>
<link rel=”stylesheet” href=”../scripts/jqwidgets/styles/jqx.base.css” type=”text/css” />
<script type=”text/javascript” src=”../scripts/jquery-2.0.3.min.js”></script>
<script type=”text/javascript” src=”../scripts/knockout-2.3.0.js”></script>
<script type=”text/javascript” src=”../scripts/jqwidgets/jqx-all.js”></script><script type=”text/javascript”>
$(document).ready(function() {
var data = {};
data.testDate1 = new Date(“2014-01-01″);
data.testDate2 = null;
data.testDate3 = new Date(null);
ko.applyBindings(new ViewModel(data));
});function ViewModel(data) {
var self = this;
self.testDate1 = ko.observable(data[‘testDate1’]);
self.testDate2 = ko.observable(data[‘testDate2’]);
self.testDate3 = ko.observable(data[‘testDate3’]);
}
</script></head>
<body>
<div data-bind=”jqxDateTimeInput: {value: testDate1, width: ‘233px’,height: ’25px’, formatString: ‘d’}”></div><br>
<div data-bind=”jqxDateTimeInput: { value: testDate2, width: ‘233px’, height: ’25’, allowNullDate: true, formatString: ‘d’}”></div><br>
<div data-bind=”jqxDateTimeInput: {value: testDate3, width: ‘233px’, height: ’25’, formatString: ‘d’}”></div>
</body>
</html>Hi bmg125,
allowNullDate is true by default. In all the widgets you use the default Format String.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/The dates that start with a value have a format of MM/dd/yyyy. The one that starts with a null will have a format of dd/MM/yyyy.
‘d’ or small format is MM/dd/yyyy which is different from the default or dd/MM/yyyy. Or at least that is my understanding. If you change the format to be MM/dd/yyyy the problem persists.The problem isn’t with the ‘AllowNullDates’ it is when the actual value starts as a null, the format is given the default and not the correct format of MM/dd/yyyy.
Thanks!
-BretHi Bret,
‘d’ is not MM/dd/yyyy. This depends on where you are i.e your Time Zone and Culture. When the value is NULL the widget displays Empty String or at least that is in the Current version.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Have you tried the example code to see what I am trying to explain? I can’t tell if I am not being clear in the description or if you are saying this is working as designed.
Is there a way to get the value to display consistently for me? This seems like a problem where the widget is not able to correctly handle the integration between Knockoutjs when the initial value is null.
I understand that the date format is localized, but in my settings the short version of a date is MM/dd/yyyy not dd/MM/yyyy. dd/MM/yyyy which is what is showing up when the initial value is null and a date is set. This is not the expected behavior because the date format is set to MM/dd/yyyy.
If the dateFormat is set to something, the date should always display in that format. This is the not case and seems like a problem.
Thanks!
-BretHere is an example. The bottom date picker had an initial value of null. When a date is set, it isn’t formatted consistently with the format chosen. Both pickers are set to the same day (January 31st).
-
AuthorPosts
You must be logged in to reply to this topic.