[CLOSED] Set value to timefield

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Set value to timefield

    I have a timefield

     X.TimeFieldFor(obj => obj.ApplicationStartTime)
                                            .EmptyText("Select")
                                            .MinTime(TimeSpan.FromHours(9))
                                            .MaxTime(TimeSpan.FromHours(18))
                                            .Increment(30)
                                            .Format("hh:mm tt")
                                            .FieldLabel("Start Time")
                                            .AnchorHorizontal("100%")
                                            .AllowBlank(false)
                                            .LabelWidth(125)
                                            .Editable(false)
                                            .SelectOnFocus(true)
                                            .Triggers(
                                            Html.X().FieldTrigger().Icon(TriggerIcon.Clear).Qtip("Remove selected")
                                            )
                                            .Listeners(l =>
                                            {
                                                l.TriggerClick.Handler = "this.clearValue();";
                                            })
    I want to fill this from database value,I fetch 9:00AM from database and try to set with bellow code

    X.GetCmp<TimeField>("ApplicationStartTime").SetValue(_tbl_Admin_ApplicationTime_Settings.str_ApplicationStartTime);
    but its through an error
    Specified cast is not valid.
    please let me know correct procedure.
    Last edited by Daniil; Aug 06, 2014 at 7:43 AM. Reason: [CLOSED]
  2. #2
    It means that your string is not recognized as time

    First, if you use X.GetCmp then you need to pass Format string because GetCmp returns only proxy object which doesn't know about real properties
    X.GetCmp<TimeField>("TimeField1", new TimeField.Config() { Format = "hh:mm tt" }).SetValue("9:00AM");
    But please ensure that your string is matched to Format, you can check it use the following code
    DateTime.ParseExact(value, formatString);
    I suggest do not use SetValue but use SelectedTime property which accepts TimeSpan, so just convert your string to TimeSpan and set to SelectedTime property
  3. #3
    Hi Vladimir
    I tried with

     X.GetCmp<TimeField>("ApplicationStartTime").SelectedTime = TimeSpan.ParseExact("9:00 AM", "hh:mm tt", null);
    but give the same error

    Input string was not in a correct format.
    .Please help.
  4. #4
    but give the same error
    In your first example the error was:

    Specified cast is not valid.
    And now the error is:

    Input string was not in a correct format.
    It seems like two different errors and two different problems?

    Are you 100% sure your input string is the correct format? This doesn't appear to be an issue with Ext.NET code.
    Geoffrey McGill
    Founder
  5. #5
    I post exact what I write in my code.previously vladimir suggest me,and I set SelectedTime property with

    TimeSpan.ParseExact("9:00 AM", "hh:mm tt", null)
    but still I facing the problem.
    Last edited by matrixwebtech; Aug 05, 2014 at 5:26 PM.
  6. #6
    I don't think that "AM" is a legal thing for a TimeSpan. A TimeSpan is actually a time interval.

    Also you probably need to escape the ":" character.
    TimeSpan.ParseExact("09:00", "hh\\:mm", null)
    See also
    http://msdn.microsoft.com/en-US/libr...vs.110%29.aspx
    http://msdn.microsoft.com/en-US/libr...vs.110%29.aspx
  7. #7
    Hi Daniil

    I simply try this

    VIEW

    @using Ext.Net
    @using Ext.Net.MVC
    @{
        Layout = null;
        var X = Html.X();
    }
    <script>
        var validation = function () {
    
            if (Ext.getCmp("f").isValid() == true) {
                return true;
            }
            else {
                return false;
            }
        }
    
    </script>
    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Index</title>
    </head>
    <body>
        <div>
            @X.ResourceManager()
            
            @(X.FormPanel().Border(false).ButtonAlign(Alignment.Left).ID("f")
            .Items(
           
             X.TimeField().ID("tf1")
                                           .EmptyText("Select")
                                           .MinTime(TimeSpan.FromHours(9))
                                           .MaxTime(TimeSpan.FromHours(18))
                                           .Increment(30)
                                           .Format("hh:mm tt")
                                           .FieldLabel("Start Time")
                                           .AnchorHorizontal("100%")
                                           .AllowBlank(false)
                                           .LabelWidth(125)
                                           .Editable(false)
                                           .SelectOnFocus(true)
                                           .Triggers(
                                           Html.X().FieldTrigger().Icon(TriggerIcon.Clear).Qtip("Remove selected")
                                           )
                                           .Listeners(l =>
                                           {
                                               l.TriggerClick.Handler = "this.clearValue();";
                                           })
           
            )
           
            .Buttons
            (
            X.Button().DirectClickAction("test")
                    .Listeners(l => { l.Click.Handler = "return validation()"; })
    
    
                )
                )
           
    
    
    </div>
    </body>
    </html>
    CONTROLLER

    public ActionResult Index()
            {
                X.GetCmp<TimeField>("tf1").SelectedTime = TimeSpan.ParseExact("9:00", "hh\\:mm", null);
                
                return View();
            }
    but still now the error is there

    Input string was not in a correct format.
  8. #8
    Your piece of code
    TimeSpan.ParseExact("9:00", "hh\\:mm", null)
    and mine
    TimeSpan.ParseExact("09:00", "hh\\:mm", null)
    are different.
    Last edited by Daniil; Aug 06, 2014 at 7:23 AM.
  9. #9
    What difference between 2 codes,but tried with yours and again get the same error.
  10. #10
    Oh, sorry, I posted the same. Corrected now, please review.
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] [1.1] TimeField
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 25, 2011, 9:33 PM
  2. TimeField - Help
    By Jose Pereira dos anjos Júnior in forum 1.x Help
    Replies: 0
    Last Post: Jun 07, 2010, 2:09 AM
  3. [FIXED] [0.8.3] TimeField Bug (New)
    By Timothy in forum Bugs
    Replies: 9
    Last Post: Feb 19, 2010, 2:23 AM
  4. [CLOSED] [0.8.3] TimeField Bug
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Feb 05, 2010, 3:31 PM
  5. TimeField
    By jmilton in forum 1.x Help
    Replies: 0
    Last Post: May 27, 2009, 12:21 PM

Posting Permissions