So I'm using the DatePicker control for a field that only requires the month and year. I have the behavior of the popup working properly, by setting the Start and Depth to "Year". In doing so, I ran into a problem where the month would be different than the one I selected. I'm not sure if it was this issue, or an issue where, because the date was coming down as the first of the month, the server was on GMT, and the client was GMT-4. So when it got client-side, the date came back as the last day of the previous month at 8pm.
I solved this problem by intercepting the date during inserts on the server, setting it to the 10th of the month and year at Noon, and then saving it. This should have solved the problem, but when I use the DatePicker in a Grid (MVC or Web), the cell goes red once I leave it, whether I actually changed the date or not. This is *extremely * confusing to my end users, and given that I am using the MVC grid, subclassing it with my own functionality is not necessarily an option.
The problem lies in how the textbox blur function works, and how it compares values. When it has the following ParseFormats:
I believe that the blur function should work in a vastly different way. It should break down the date into its various components, and call the set methods on the old value, instead of just doing a wholesale replacement on the date value. In this example, the function cycle through each component of the date, checking if any of the ParseFormats contain the string representation of that part (d, m, y, etc). If it does, it should call the getXXX method of the old date, and compare it to the getXXX method of the new date. If they are different, it should call setXXX on that component alone, instead of doing a wholesale replacement of the current value of the control.
I know that this would complicate the blur function a bit, but it would more accurately represent how the picker should work, given the already-built-in ability to adjust the depth of the control.
Please let me know if you have any questions or need code to reproduce the issue.
Thanks!
I solved this problem by intercepting the date during inserts on the server, setting it to the 10th of the month and year at Noon, and then saving it. This should have solved the problem, but when I use the DatePicker in a Grid (MVC or Web), the cell goes red once I leave it, whether I actually changed the date or not. This is *extremely * confusing to my end users, and given that I am using the MVC grid, subclassing it with my own functionality is not necessarily an option.
The problem lies in how the textbox blur function works, and how it compares values. When it has the following ParseFormats:
.ParseFormats(new[] {"MM/yyyy", "MM yyyy"})
the DateTime object in the browser doesn't have a day to assign, so it assumes the first of the month. When you leave the field, the function simply compares the old value to the new one, sees that the old day (the 10th) is different from the new day (the 1st) and changes the value, which bubbles back to the DataSource, and tells the Grid the data has changed.I believe that the blur function should work in a vastly different way. It should break down the date into its various components, and call the set methods on the old value, instead of just doing a wholesale replacement on the date value. In this example, the function cycle through each component of the date, checking if any of the ParseFormats contain the string representation of that part (d, m, y, etc). If it does, it should call the getXXX method of the old date, and compare it to the getXXX method of the new date. If they are different, it should call setXXX on that component alone, instead of doing a wholesale replacement of the current value of the control.
I know that this would complicate the blur function a bit, but it would more accurately represent how the picker should work, given the already-built-in ability to adjust the depth of the control.
Please let me know if you have any questions or need code to reproduce the issue.
Thanks!