Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1005
h:mm tt and the igDateEditor
posted

If I prepopulate my HTML control as follows:

@Html.TextBox(string.Empty, Model.Value.ToString("h:mm tt"), new { @class = "form-control timecontrol", @type = "time" })

and then initialize my igDateEditor as follows:

$('.timecontrol').igDateEditor({ dateInputFormat: "h:mm tt", dateDisplayFormat: "h:mm tt", width: "100%", allowNullValue: true, buttonType: "spin" });

When I select the control to edit the value the editor goes blank and I lose the value set via my @Html.TextBox call.

If I change my MVC text box call to the following it works but obviously flashes the full date value for a second first:

@Html.TextBox(string.Empty, Model.Value.ToString(), new { @class = "form-control timecontrol", @type = "time" })

Parents
No Data
Reply
  • 2895
    posted

    Hello Dr Tone,

    Thank you for using our community.

    Let me firs answer your first question. When you use string value for the “value” option, the editor uses the JavaScript constructor to create a date object out of it. The format that you use is not recognized by JavaScript as a valid way to set a value ant that is why your attempt to set a value this way fails. What I mean is if the time you set is like this “12:20 AM”, the JavaScript constructor will look like this new Date("12:20 AM") and this returns “Invalid Date”.

    What I can suggest you to do is use our MVC wrappers. That way you will be able to set the date directly to the editor and the date value won’t flash. The following code demonstrates how to use our MVC wrapper for igDateEditor:

    @(Html.Infragistics().DateEditor()

           .DateInputFormat("h:mm tt")

           .DateDisplayFormat("h:mm tt")

           .AllowNullValue(true)

           .ButtonType(TextEditorButtonType.Spin)

           .Value(Model)

           .Render())

    If you have any other questions, let me know.

    Best Regards,
    Marina Stoyanova,
    Software Developer,
    Infragistics, Inc.

Children