PDA

View Full Version : [CLOSED] DateTimePicker



ehmdb
Jul 25, 2013, 4:42 PM
2 Questions:
1) is there a viable DateTimePicker option that can bind to a .Net DateTime object?
2) why can't I bind a TimeSpan object to a TimeFields? Get invalid cast when try to retrieve the value

Model

[Field(FieldLabel = "Pickup Date", LabelAlign = LabelAlign.Right)]
public DateTime PickupDate { get; set; }

View

X.TimeFieldFor(m => m.PickupTime).Format("HH:mm"),

Controller

TimeField tf = this.GetCmp<TimeField>("PickupTime")
tf.SelectedTime' threw an exception of type 'System.InvalidCastException'

Baidaly
Jul 26, 2013, 12:54 AM
Hello!

Thank you! We are investigating!

Daniil
Jul 26, 2013, 9:00 AM
Hi @ehmdb,

Welcome to the Ext.NET forums!



1) is there a viable DateTimePicker option that can bind to a .Net DateTime object?


Do you mean a TimeField under "DateTimePicker"? Yes, we should consider a possibility to support a DateTime to bind to a TimeField. Thank you for the question.



2) why can't I bind a TimeSpan object to a TimeFields? Get invalid cast when try to retrieve the value


Please clarify how do you submit it?

What about this way?
http://mvc.ext.net/#/Models/FormPanelFor/

ehmdb
Jul 29, 2013, 1:53 PM
Apologies, yes I am referring to a TimeFieldFor as follows:


[Field(FieldLabel = "Pickup Time", LabelAlign = LabelAlign.Right)]
public TimeSpan PickupTime { get; set; }


X.TimeFieldFor(m => m.PickupTime).Format("HH:mm"),


TimeField tf = this.GetCmp<TimeField>("PickupTime");

submit code is


X.Button().Text("Save").PaddingSpec("5 5 5 5 ").MarginSpec("0 10 0 0")
.DirectEvents(de =>
{
de.Click.Url = Url.Action("DirectEventSubmit");
de.Click.EventMask.ShowMask = true;
de.Click.FormID = "FormOrderEntrySummary";
})

Daniil
Jul 29, 2013, 3:43 PM
Thank you. I reproduced it with the test case below. We will investigate what we can do.

View

@model Work2MVC.Models.BindModel

@{
var X = Html.X();
}

<!DOCTYPE html>
<html>
<head>
<title>Ext.Net.MVC v2 Example</title>
</head>
<body>
@X.ResourceManager()

@(X.Button()
.Text("Save")
.DirectEvents(de =>
{
de.Click.Url = Url.Action("Submit");
de.Click.FormID = "FormPanel1";
})
)


@(X.FormPanel()
.ID("FormPanel1")
.Items(
X.TimeFieldFor(m => m.PickupTime)
)
)
</body>
</html>


Model

using Ext.Net.MVC;
using System;

namespace Work2MVC.Models
{
public class BindModel
{
[Field(FieldLabel = "Pickup Time")]
public TimeSpan PickupTime { get; set; }
}
}

Controller

using System;
using System.Web.Mvc;
using Ext.Net;
using Ext.Net.MVC;
using Work2MVC.Models;

namespace Work2MVC.Controllers
{
[DirectController]
public class RazorController : Controller
{
public ActionResult Index()
{
return View(new BindModel() { PickupTime = DateTime.Now.TimeOfDay });
}

public ActionResult Submit()
{
TimeField tf = this.GetCmp<TimeField>("PickupTime");
X.Msg.Alert("PickupTime", tf.SelectedTime).Show();

return this.Direct();
}
}
}


However, I would suggest you to leverage the following way to retrieve the things from POST.

public ActionResult Submit(BindModel entity)
{
X.Msg.Alert("PickupTime", entity.PickupTime).Show();

return this.Direct();
}

Daniil
Jul 30, 2013, 9:48 AM
Yes, we should consider a possibility to support a DateTime to bind to a TimeField. Thank you for the question.

Ive just made the following commit to the SVN trunk.

[UPDATE] Now a TimeField can apply a DateTime property from a Model (related to FormPanelFor and TimeFieldFor helpers).

[UPDATE] Now a Model's TimeSpan property is bound to a TimeField, instead of a TextField. I.e. it doesn't require a "FieldType=typeof(TimeField)" attribute for the Model's property. (related to FormPanelFor and TimeFieldFor helpers)

Thank you again for the question.

ehmdb
Jul 30, 2013, 11:29 PM
Thanks, the recompile works.

Daniil
Aug 01, 2013, 3:50 AM
The issue with

X.GetCmp<TimeField>("PickupTime").SelectedTime
should be fixed in SVN.

Thank you again for the report.