mindparse
mindparse

Reputation: 7235

Sencha Touch 2 - Setting a max date on a datepicker

Does anyone have any idea's how to prevent a user picking a future date (greater than current date) on a datepicker field?

I know I can validate easily enough after the user clicks the done button on the picker and show them an alert message telling them they cannot pick a future date.

But it would be nice if there was some way to actually prevent the selection in the first place, such as disabling some of the slot values from selection. I'm not so sure this can be done, maybe validation is the only way?

Upvotes: 0

Views: 1193

Answers (2)

Sagar Khatri
Sagar Khatri

Reputation: 1014

As I dont have enough reputation so I need to add my comments as an answer.

You have two ways to do this.

  1. Listen to the change event and hide the donebutton if the date is greater than max date.
  2. Override the Ext.picker.Date and hide the date values in the picker itself which are greater than max date at the initialization time.

2nd option is a bit complex but worth it if this feature is most important.

Upvotes: 1

Rob Schmuecker
Rob Schmuecker

Reputation: 8954

You can at the very least limit the yearFrom and yearTo this is however only available as a documented config in the Ext.picker.Date class which is actually the underlying class that gets called when creating an Ext.field.DatePickerinstance. You can set options for the Ext.picker.Date by passing in the options to the picker property of the field

http://docs-origin.sencha.com/touch/2.4/2.4.1-apidocs/#!/api/Ext.field.DatePicker-cfg-picker

e.g.

    Ext.create('Ext.form.Panel', {
        fullscreen: true,
        items: [{
            xtype: 'fieldset',
            items: [{
                xtype: 'datepickerfield',
                label: 'Birthday',
                name: 'birthday',
                value: new Date(),
                picker:{
                    yearFrom:2000,
                    yearTo:2020
                }
            }]
        }]
    });

Upvotes: 0

Related Questions