PDA

View Full Version : How to set a date with javascript



zagam
Mar 05, 2015, 9:53 AM
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(r aw.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

RCN
Mar 06, 2015, 4:54 PM
Use DateField's SetValue instead of SetData.

SetValue: http://docs.sencha.com/extjs/5.0.1/#!/api/Ext.form.field.Date-method-setValue
SetData: http://docs.sencha.com/extjs/5.0.1/#!/api/Ext.Component-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.

lrossism
Mar 08, 2015, 1:25 AM
Hi, use this code:


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

zagam
Mar 09, 2015, 8:19 AM
Thank you!!! I used the method of @lrossism and work fine!!

@RCN @lrossism thank you very much thanks for the help!!!

RCN
Mar 09, 2015, 12:37 PM
You're welcome

lrossism
Mar 09, 2015, 8:10 PM
Thats ok...