View Full Version : How to set a date with javascript

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_txtDataScadenza.setData(r aw.DataScadenza);


Client side i declare the element in this mode:

<ext:FieldContainer ID="FieldContainer6" runat="server" Layout="HBoxLayout">
<ext:DateField ID="txtDataScadenza" runat="server" MarginSpec="0 0 0 20" ValidateOnChange="False" ValidateOnBlur="False"
Flex="2" />

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.

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>
<head runat="server">
<ext:ResourceManager runat="server" />
<ext:Button Text="Set Date" runat="server">
<Click Handler="App._dfd.setValue(new Date());" />
<ext:Button Text="Clear Date" runat="server">
<Click Handler="App._dfd.setValue(null);" />
<ext:DateField ID="_dfd" runat="server" />

Let me know if you need further assistance.

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

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

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!!!

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

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