Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: DatePicker starts at 1980?

  1. #1
    Sencha Premium Member
    Join Date
    Sep 2008
    Posts
    710
    Vote Rating
    6
      0  

    Default DatePicker starts at 1980?

    I have the need to allow the user to enter their age in a date picker field, but it starts at 1980....any way to override this? Shouldn't this be a config value?

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      0  

    Default

    specify the yearFrom config param. It defaults to 1980
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha Premium Member
    Join Date
    Sep 2008
    Posts
    710
    Vote Rating
    6
      0  

    Default

    First off, the config param is not specified in the API. Secondly, when used, it still doesn't work for me for some reason. The DatePicker renders, but still default to 1980. Showing the picker is conditional for me, so I'm using the following code:

    Code:
            // Need to add age verification fields if alcohol in product
            if(this.productData.containsAlcohol)
            {
                items.push(
                    {
                        html: 'Please enter your date of birth to verify that you are 21 years or older:',
                        style: 'font-size: .8em;margin-top: 10px'
                    },
                    {
                        id: 'age_date_picker2',
                        xtype: 'datepickerfield',
                        label: 'Enter Age',
                        yearFrom: 1970
                    }            
                )            
            }

  4. #4
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      0  

    Default

    It is and it isn't. DatePickerField is just an extension of Field that pops up a DatePicker. So yearFrom is a config of DatePicker, not DatePickerField. You can tell tell DatePickerField what picker to use by specifying the picker param on DatePickerField.

    This is in the source for the DatePickerField that may shed some light:

    Code:
    this.datePicker = new Ext.DatePicker(Ext.apply(this.picker || {}));
    line 63 of /src/widgets/form/DatePicker.js

    so try this:

    Code:
    {
        xtype: "datepickerfield",
        id: "age_date_picker2",
        label: "Enter Age",
        picker: { yearFrom: 1970 }
    }
    Should work like that if I remember
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  5. #5
    Sencha Premium Member
    Join Date
    Sep 2008
    Posts
    710
    Vote Rating
    6
      0  

    Default

    Ok, so I guess I have to do the following then:

    Code:
            var dp = new Ext.DatePicker({
                yearFrom: 1970
            });
    
            // Need to add age verification fields if alcohol in product
            if(this.productData.containsAlcohol)
            {
                items.push(
                    {
                        html: 'Please enter your date of birth to verify that you are 21 years or older:',
                        style: 'font-size: .8em;margin-top: 10px'
                    },
                    {
                        id: 'age_date_picker',
                        xtype: 'datepickerfield',
                        label: 'Enter Age',
                        picker: dp
                    }            
                )            
            }
    Thank for the pointer

  6. #6
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      0  

    Default

    No, the source I provided shows that it is just expecting an object

    Code:
    new Ext.DatePicker(Ext.apply(this.picker || {}));
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  7. #7
    Sencha Premium Member
    Join Date
    Sep 2008
    Posts
    710
    Vote Rating
    6
      0  

    Default

    Not following what you mean by that. I know you were just showing me the source. The Ext.DatePicker object won't render in a form though, so I have to use the xtype: 'datepickerfield', and then specify the picker to use. The above code works fine in my form and does what i need, unless you see a problem with doing it this way.

  8. #8
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      0  

    Default

    Code:
    var form = new Ext.form.FormPanel({
    	fullscreen: true,
    	items: [
    		{
    			xtype: "datepickerfield",
    			label: "Enter Age",
    			picker: { yearFrom: 1970 }
    		}
    	]
    });
    This now makes the year start at 1970. The picker object is just the configuration object for the underlaying DatePicker.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  9. #9
    Sencha Premium Member
    Join Date
    Sep 2008
    Posts
    710
    Vote Rating
    6
      0  

    Default

    Ah...I gotcha. Thought the property was expecting a full fidelity object. Passing a config is much cleaner. Thanks again.

  10. #10
    Sencha Premium Member
    Join Date
    Sep 2008
    Posts
    710
    Vote Rating
    6
      0  

    Default

    A related question: Is there any way to set the picker slot values without setting the field value of the picker? For instance I want people to be able to enter their date of birth back to 1900 but I don't really want the picker to start at 1900. From the look at the source, it doesn't look like it as it looks like passing a config object of {month:1 , day:1, year:2000} will set both the picker and the field.

Page 1 of 2 12 LastLast

Similar Threads

  1. 'Contains' instead of 'Starts with' in ComboBox autocomplete
    By ngd in forum Ext 2.x: Help & Discussion
    Replies: 10
    Last Post: 6 Jun 2013, 10:28 PM
  2. IE - Checkbox in a toolbar starts Unchecked
    By henrique-suave in forum Ext 1.x: Help & Discussion
    Replies: 3
    Last Post: 27 Jun 2007, 9:12 PM
  3. Progress bar starts at the middle in IE
    By rjanos in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 13 Jun 2007, 3:20 PM
  4. How can I know when a drag starts from a grid?
    By Jonathan Feinberg in forum Ext 1.x: Help & Discussion
    Replies: 4
    Last Post: 23 Apr 2007, 12:40 PM

Posting Permissions

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