PDA

View Full Version : DateField setValue



scgrif32
23 Sep 2010, 4:19 PM
Hello all,

I am rather new to Ext Js and not as comfortable with this language as I would like to be so I am turning to you for help. I am not finding examples of how to set the default value for the date field after it is rendered. I have tried to attach an event "afterrender" like such:


var fromdate = new Ext.form.DateField({
allowBlank: false,
blankText: 'This is a required field!',
editable: false,
fieldLabel: 'From',
id: 'start-date',
msgTarget: 'side',
name: 'start-date',
showToday: false,
vtype: 'daterange',
endDateField: 'end-date',
});

Ext.onReady(function(){
new Ext.Viewport({
layout: "border",
defaults: { bodyStyle: 'padding: 5px 2px;', split: false },
items: [reportFormPanel, reportGridPanel]
});
availableReportsStore.load();

var now = new Date();
fromdate.on('afterrender', function() {
this.setValue = now.format("Y-m-d");
});
});But absolutely nothing happens.

This value will be the current date in the event that the user doesn't change the value of these fields using the calendar but I want it to show up after the form has rendered in the browser.

From what I read if unchanged this value would be submitted to the server which is exactly what I want to happen.

I am certain I am missing something very basic so please forgive me if you feel this question is rather elementary. All help is much appreciated.

Thank you

evant
23 Sep 2010, 5:06 PM
Because you're not calling a method, you're actually modifying the setValue function at runtime to point to that date.

Also, there's no need to stringify it before setting it:



this.setValue(now);

scgrif32
24 Sep 2010, 7:25 AM
Evant,

Thank you for your response. After being frustrated for a while I overlooked a very novice mistake (Sorry). I have now changed my code to look like such:


Ext.onReady(function(){
new Ext.Viewport({
layout: "border",
defaults: { bodyStyle: 'padding: 5px 2px;', split: false },
items: [reportFormPanel, reportGridPanel]
});
availableReportsStore.load();

var now = new Date();
fromdate.setValue(now);
todate.setValue(now);
});Now a value exists in the field but the second date field (To date) shows the styles displayed for the text field when an error occurs for a brief second then they go away after the current date is displayed.

Is there something I can do to fix that issue?

Btw, I was unable to get the following syntax to work and am curious about whether or not I was even using the right approach?


fromdate.on('afterrender', function() {
this.setValue(now);
});
todate.on('afterrender', function() {
this.setValue(now);
});
All suggestions are encourage so I can learn better ways of implementing such.

Thank you in advance. :)