set default selected

I've inherited an application that uses ExtJS and am relatively unfamiliar with it's conventions.

I have a select box for time entry that defaults to a time passed in. Is it possible to set selected = selected for the value it defaults to? Currently the default time is displayed, but when you click on the box the list of options defaults to the first value (So if the default it 2pm, when you click to select an alternative time you are taken to 12am not 2pm).

The code:

{
            xtype: 'timefield',
            id: 'timeselect',
            name: 'starttime',
            fieldLabel: 'Start Time',
            labelWidth: 80,
            labelAlign: 'right',
            width: 160,
            minValue: '12:00 AM',
            maxValue: '11:55 PM',
            value: MyApp.config.AppConfig.time, //Current time rounded to hour
            increment: 15
        },

Thanks!

Edit: To clarify. The select box shows the correct time when the page loads. But when the user clicks on the select, they are taken to the start of the option list (12:00 am in this case). I'm hoping to have the option list default to the time selected (similar to ). Thanks!

Edit #2: The application uses v4.0.7


The solution is simple then: upgrade your version of Ext! Not that simple? Patch it in the meanwhile. I must confess that I tried to copy the code of the v4.2 of Ext.form.field.Time into the fiddle. That didn't work. Here's a cleaner approach:

Ext.define('Ext.ux.fix.Ext.form.field.Time.CurrentSelectionOnExpand', {
    override: 'Ext.form.field.Time'

    ,initComponent: function() {
        this.callParent();
        this.on({
            scope: this
            ,delay: 1 // let render
            ,expand: function() {
                this.highlightCurrent();
            } 
        });
    }

    // copied from Ext.view.BoundListKeyNav.method#highlightAt()
    ,highlightCurrent: function() {
        var me = this,
            picker = me.picker,
            index = picker.store.find('disp', me.getRawValue()),
            item = picker.all.item(index)
        if (item) {
            item = item.dom;
            picker.highlightItem(item);
            picker.getTargetEl().scrollChildIntoView(item, false);
        }
    }
});
链接地址: http://www.djcxy.com/p/88096.html

上一篇: 列页面,如何使用CSS或Javascript将左侧div增长到正确div的相同高度?

下一篇: 设置默认选中