【问题标题】:Give date picker different default value than datefield value?给日期选择器提供与日期字段值不同的默认值?
【发布时间】:2017-05-03 17:59:51
【问题描述】:

我在 Extjs 4.2 中工作,遇到了有关日期字段的问题。我想将字段的默认值设置为特定日期,但是当用户单击触发器以显示日期选择器小部件时,我希望日期选择器突出显示 当前日期 .我尝试在“expand”事件处理程序中的字段上使用 setValue 方法,但这会更改我不希望发生的 datefield 本身的值。有什么方法可以实现吗?

【问题讨论】:

    标签: javascript extjs extjs4 extjs4.2


    【解决方案1】:

    将日期选择器的 activeDate 成员设置为当前日期,然后更新选择器以显示突出显示的日期。这是在扩展事件中完成的。

    expand: function(field, opts) {
                            field.picker.activeDate = new Date();
                            field.picker.update(null, false);
                        }
    

    在下面的示例中,日期设置为 1 月 1 日。 When the picker is expanded, it is set to today.

    Ext.create('Ext.form.Panel', {
                renderTo: Ext.getBody(),
                width: 300,
                bodyPadding: 10,
                title: 'Dates',
                items: [{
                    xtype: 'datefield',
                    anchor: '100%',
                    fieldLabel: 'From',
                    name: 'from_date',
                    value: new Date(2017,0,1),
                    listeners: {
                        expand: function(field, opts) {
                            field.picker.activeDate = new Date();
                            field.picker.update(null, false);
                        }
                    }
                }]
            });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-14
      • 2013-05-12
      • 1970-01-01
      • 2011-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多