This is a migrated thread and some comments may be shown as answers.

Strange Formatting Issue

3 Answers 100 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Louis
Top achievements
Rank 1
Louis asked on 08 Apr 2014, 06:20 PM
I have a reusable view for displaying project information in a handful of places.  In two places, I use this view to update a model and send it to the server for processing.  I'm seeing some strange formatting issue with the DatetimePicker when the same view is used on different pages (see attached screenshots).  I don't explicitly apply a format string to the Datepicker, but even having done so it doesn't make a difference.  If I edit the value, the format gets applied, but on load it is incorrect.  Both of the views are being called slightly different from my controller, but return the same partial with the same model:

[HttpPost]
public ActionResult UpdateView(Project project)
{
    var pipelineProject = project;
    ViewBag.IsUpdate = true;
    return PartialView("_CreateUpdateProject", pipelineProject);
}
 
 
[HttpPost]
public ActionResult UpdateViewForProjectDocumentGuid(string projectDocumentGuid)
{
    var projectRepository = new ProjectRepository(SystemConnection, CurrentUser, WebConfigHelper.GetConfigurationValue("DefaultProgram"));
    var pipelineProject = projectRepository.Read(new ProjectSearchModel() { AccountNames = AccessibleProjects.Select(a => a.ProjectAccountName).ToList(), DocumentGuid = projectDocumentGuid}).First();
    ViewBag.IsUpdate = true;
    ViewBag.CollapseGeneral = true;
    return PartialView("_CreateUpdateProject", pipelineProject);
}

The GoodDatepickerFormat image comes from result of UpdateViewForProjectDocumentGuid and the BadDatepickerFormat comes from UpdateView,  Everything looks the same in both cases (other than UpdateView returning the DateTimes in question with a Kind of Local rather than Unspecified), and I attempted to read it exactly the same as the working case but that made no difference.  Is there any workaround to force format on the field?

3 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 10 Apr 2014, 01:38 PM
Hello Louis,

We assume this is happening because you are posting values for those two fields that the DateTimePickers present. And since this is the format in which they are posted the ModelState returns the same string representation.

Try to clear the ModelState dictionary in the action method and see if it makes a difference.

Kind Regards,
Petur Subev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Louis
Top achievements
Rank 1
answered on 10 Apr 2014, 08:36 PM
Petur,

I swapped the incorrectly formatted Controller action to take in the model from the POST and read a fresh version of it (just like the second controller in the example above) and the result is the same.  For a bit more context, I return the '_CreateUpdateProject' partial view in both cases and the partial view has a subsequent partial view where these DatePickers exist.  This still doesn't explain why the behavior is different in both places, when the content of the return is identical.

As a workaround I decided to format the fields myself on document ready and noticed that the datePicker.value() is null, while the datePicker.element[0].defaultValue contains the correct value.  It seems as if the element isn't bound correctly, and it falls back to the defaultValue.  In order to force formatting I do the following on document ready:

var finishDatepicker = $("#PipelineScheduleFinishDate").data("kendoDatePicker");
var finishDate = new Date(finishDatepicker.element[0].defaultValue);
finishDatepicker.value(finishDate);

var
startDatepicker = $("#PipelineScheduleStartDate").data("kendoDatePicker");
var startDate = new Date(startDatepicker.element[0].defaultValue);
startDatepicker.value(startDate);


This results in the value being formatted properly.
0
Petur Subev
Telerik team
answered on 14 Apr 2014, 08:26 AM
Hello Louis,

How exactly do you submit that form to the server, is it through Ajax? We assume this is happening because you post the value through Ajax (this is the UTC date format) and then you do not clear the ModelState and the value appears like this.

We will need a small replication within a sample project to investigate and give a concrete resolution to the case.

Kind Regards,
Petur Subev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Date/Time Pickers
Asked by
Louis
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Louis
Top achievements
Rank 1
Share this question
or