PDA

View Full Version : Am unable to validate date



baskar
14 Jul 2009, 9:04 PM
this is my code.am unable to validate date.i have to select next contact date.For this i have to disable all the dates before the current date.My current date field is in hidden field.How to validate this.if any one know please help me.


Ext.apply(Ext.form.VTypes, {
daterange: function (val, field) {
var date = field.parseDate(val);
if (!date) {
return;
}
if (field.startDateField && (!this.dateRangeMax || (date.getTime() != this.dateRangeMax.getTime()))) {
var start = Ext.getCmp(field.startDateField);
start.setMaxValue(date);
start.validate();
this.dateRangeMax = date;
}
else if (field.endDateField && (!this.dateRangeMin || (date.getTime() != this.dateRangeMin.getTime()))) {
var end = Ext.getCmp(field.endDateField);
end.setMinValue(date);
end.validate();
this.dateRangeMin = date;
}
return true;
}
});
Ext.onReady(function () {
Ext.QuickTips.init();
function getsqlformate1(val, HtmlElement) {
var dt1 = new Date(val.substr(0, 2) + "/" + val.substr(3, 3) + "/" + val.substr(7, 10));
dt1 = dt1.format('Y-m-d');
document.getElementById('dt_next_contact').value = dt1;
document.getElementById(HtmlElement).value = dt1;
}
var lead = "lead";
Ext.form.Field.prototype.msgTarget = 'side';

var bd = Ext.getBody();

var Lead = new Ext.FormPanel({
id: 'Lead',
labelAlign: 'left',
frame: 'true',
layout: 'fit',
renderTo: 'CtlLead',
deferredRender: true,
layout: 'form',
header: false,
title: ' New Lead',
labelWidth: 120,
autoHeight: true,
width: 900,
items: [{
layout: 'form',
border: false,
items: [{
layout: 'column',
border: false,
height: 175,
items: [{
columnWidth: .5,
layout: 'form',
border: false,
items: [{
xtype: 'hidden',
name: 'lead_created_on',
id: 'lead_created_on',
value: Lead_dates
},{
xtype: 'hidden',
name: 'dt_next_contact',
id: 'dt_next_contact',
value: ContactNextDate
},
{
xtype: 'hidden',
value: '2009-07-14',
vtype: 'daterange',
endDateField: 'dtnext_contact',
parseDate: function (v) {
return Date.parseDate(v, 'Y-m-d');
}
},{
id: 'dtnext_contact',
xtype: 'datefield',
labelSeparator: '',
format: 'd-M-Y',
fieldLabel: 'Next Contact',
value: ContactNextDate,
width: 280,
tabIndex: '16',
name: 'dtnext_contact',
listeners: {
'change': function () {
getsqlformate1(this.value, 'dt_next_contact')
}
}
}]
}
]

}]
}]
});

Lead.render(document.body);

});

makana
14 Jul 2009, 11:22 PM
How many threads with the same issue do you want to start again?
This is your thread, where Condor helped you out with this: http://extjs.com/forum/showthread.php?t=74185

If the current date in your meaning is "today", then just set

minValue: new Date()
to your next contact field and leave the hidden stuff.

If the current date in your meaning isn't necessarily today but something else from db or so and you necessarily need your hidden field, then use the daterange vtype, like Condor said:


Ext.apply(Ext.form.VTypes, {
daterange : function(val, field) {
var date = field.parseDate(val);
if(!date){
return;
}
if (field.startDateField && (!this.dateRangeMax || (date.getTime() != this.dateRangeMax.getTime()))) {
var start = Ext.getCmp(field.startDateField);
start.setMaxValue(date);
start.validate();
this.dateRangeMax = date;
}
else if (field.endDateField && (!this.dateRangeMin || (date.getTime() != this.dateRangeMin.getTime()))) {
var end = Ext.getCmp(field.endDateField);
end.setMinValue(date);
end.validate();
this.dateRangeMin = date;
}
return true;
}
});

and set the ids properly!!:

{
id: 'current_date',
xtype: 'hidden',
value: '2009-07-14',
vtype: 'daterange',
endDateField: 'dtnext_contact'
},{
id: 'dtnext_contact',
xtype: 'datefield',
labelSeparator: '',
format: 'd-M-Y',
fieldLabel: 'Next Contact',
value: ContactNextDate,
width: 280,
tabIndex: '16',
name: 'dtnext_contact',
startDateField: 'current_date',
listeners: {
'change': function () {
getsqlformate1(this.value, 'dt_next_contact')
}
}
}

Btw, I would format the date for sql server-side.