How to set a date with javascript

  1. #1

    How to set a date with javascript

    Hello everyone!!!!

    I have a javascript file where i take a value from a grid to populate the field of a particular screen.

    var chargeIntermediario = function ()
    {
        var raw = App.Main_usrGridIntermediari_grigliaIntermediario.getSelection()[0].raw;
        App.Main_usrIntermediari_txtId.setValue(raw.Id);
        
        App.Main_usrIntermediari_txtDataScadenza.setData(raw.DataScadenza);
        
    }
    Client side i declare the element in this mode:
    <ext:FieldContainer ID="FieldContainer6" runat="server" Layout="HBoxLayout">
                        <Items>
                             <ext:DateField ID="txtDataScadenza" runat="server" MarginSpec="0 0 0 20" ValidateOnChange="False" ValidateOnBlur="False"
                                                   Flex="2" />
                        </Items>
    </ext:FieldContainer>
    All element in my code have the same declaration, and each element correctly loads the data , with the exception of types datatime that have the value setting to 'null'.

    how can I set the value correctly?

    Thank you very much and sorry for english.
    Paolo
    Last edited by zagam; Mar 06, 2015 at 8:15 AM.
  2. #2
    Use DateField's SetValue instead of SetData.

    SetValue: http://docs.sencha.com/extjs/5.0.1/#...ethod-setValue
    SetData: http://docs.sencha.com/extjs/5.0.1/#...method-setData

    <!DOCTYPE html>
    <html>
    <head runat="server">
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:Button Text="Set Date" runat="server">
            <Listeners>
                <Click Handler="App._dfd.setValue(new Date());" />
            </Listeners>
        </ext:Button>
        <ext:Button Text="Clear Date" runat="server">
            <Listeners>
                <Click Handler="App._dfd.setValue(null);" />
            </Listeners>
        </ext:Button>
        <ext:DateField ID="_dfd" runat="server" />
    </body>
    </html>
    Let me know if you need further assistance.
  3. #3
    Hi, use this code:

    App.Main_usrIntermediari_txtDataScadenza.setValue(new Date(raw.DataScadenza));
  4. #4

    Thank you all !! works fine

    Thank you!!! I used the method of @lrossism and work fine!!

    @RCN @lrossism thank you very much thanks for the help!!!
  5. #5
    You're welcome
  6. #6
    Thats ok...

Similar Threads

  1. Replies: 8
    Last Post: May 20, 2013, 4:01 AM
  2. Replies: 3
    Last Post: May 09, 2012, 4:28 PM
  3. Replies: 2
    Last Post: Apr 23, 2012, 12:47 PM
  4. Replies: 1
    Last Post: Apr 13, 2012, 1:52 PM
  5. Replies: 3
    Last Post: Mar 20, 2009, 3:58 PM

Posting Permissions