Results 1 to 2 of 2

Thread: Am unable to validate date

  1. #1

    Exclamation Am unable to validate date

    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.

    Code:
    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);
       
    });

  2. #2
    Sencha User makana's Avatar
    Join Date
    Apr 2008
    Location
    Dresden, Germany
    Posts
    527

    Default

    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
    Code:
    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:
    Code:
    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!!:
    Code:
    {
    	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.
    Programming today is a race between software engineers striving to build bigger and better ?diot-proof programs, and the universe striving to produce bigger and better idiots. So far, the universe is winning. (Rick Cook)

    Enhanced ExtJS adapter for Adobe AIR

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •