Results 1 to 7 of 7

Thread: set minDate to value from another dateField?

  1. #1
    Sencha User NightAvatar's Avatar
    Join Date
    Nov 2008
    Location
    Norway
    Posts
    206

    Default set minDate to value from another dateField?

    Is there a way to set the minDate for dateField 2 to be the value of dateField 1 (if set)?

  2. #2
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,892

    Default

    See /examples/form/adv-vtypes.html in your installation directory

  3. #3
    Sencha User NightAvatar's Avatar
    Join Date
    Nov 2008
    Location
    Norway
    Posts
    206

    Default

    Duh. Sorry, I forgot about that. Thanks!

  4. #4
    Sencha User NightAvatar's Avatar
    Join Date
    Nov 2008
    Location
    Norway
    Posts
    206

    Default

    Ok, I've looked at the example and don't comprehend the magic.

    I hope somebody can demystify it for me.

    Looks like the code is
    Code:
    // Add the additional 'advanced' VTypes
    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;
            }
            /*
             * Always return true since we're only using this vtype to set the
             * min/max allowed values (these are tested for after the vtype test)
             */
            return true;
        }
    });
    
    Ext.onReady(function(){
    
            /*
             * ================  Date Range  =======================
             */
        
        var dr = new Ext.FormPanel({
          labelWidth: 125,
          frame: true,
          title: 'Date Range',
          bodyStyle:'padding:5px 5px 0',
          width: 350,
          defaults: {width: 175},
          defaultType: 'datefield',
          items: [{
            fieldLabel: 'Start Date',
            name: 'startdt',
            id: 'startdt',
            vtype: 'daterange',
            endDateField: 'enddt' // id of the end date field
          },{
            fieldLabel: 'End Date',
            name: 'enddt',
            id: 'enddt',
            vtype: 'daterange',
            startDateField: 'startdt' // id of the start date field
          }]
        });
    
        dr.render('dr');
        
    });
    EDIT: So the red parts are my field IDs?

    I'll try this out and post back the results.

  5. #5
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,892

    Default

    ? in the field that's being validated just like in the example.

  6. #6
    Sencha User NightAvatar's Avatar
    Join Date
    Nov 2008
    Location
    Norway
    Posts
    206

    Default

    I find that example very confusing because it uses panels which I do not want to do.

    Can somebody please explain it to me in a way I can implement such a feature into existing fields in my html like these:
    Code:
    <label for="fromDate">From date:</label>
    <input type="text" id="fromDate" />
    
    <label for="toDate">To date:</label>
    <input type="text" id="toDate" />
    EDIT: In other words, how do I code the above example to know my field Id's? I don't want to use panels so I don't know which parts of the code to use and which I don't need.

  7. #7
    Ext User
    Join Date
    May 2010
    Location
    Madurai,TN, India
    Posts
    9

    Default

    In need of same requirement as above. Want to dynamically set date range for the two different datefields.

Posting Permissions

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