You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ext JS 7.2双Datepicker组件切换时选中值异常问题求助

Fix for Ext JS 7.2 Datepicker Value Mismatch When Switching Between Components

I’ve dug into the issue you described where switching between two Datepicker components on the same page leads to incorrect selected values. This is a common edge case tied to Ext JS’s default performance optimization behavior, and here’s a straightforward fix:

Root Cause

By default, Ext JS reuses a single picker panel instance across multiple Datepicker components to save resources. When you toggle between the two components, the picker’s internal state (like the currently selected date) doesn’t reset properly. This causes the first Datepicker to display the second component’s value when you switch back to it.

Solution

Add the destroyPickerOnHide: true configuration to each of your Datepicker components. This setting ensures each Datepicker destroys its picker panel when hidden, and creates a fresh, clean instance when opened again—completely isolating the state between the two components.

Modified Code Example

Ext.create('Ext.form.Panel', {
    renderTo: Ext.getBody(),
    width: 400,
    bodyPadding: 10,
    items: [
        {
            xtype: 'datefield',
            fieldLabel: 'First Date',
            name: 'firstDate',
            destroyPickerOnHide: true // Ensure picker is destroyed on hide
        },
        {
            xtype: 'datefield',
            fieldLabel: 'Second Date',
            name: 'secondDate',
            destroyPickerOnHide: true // Isolate this component's picker state
        }
    ]
});

Verification

After applying this change, follow your original reproduction steps:

  • Click the first Datepicker’s icon to open its picker
  • Click the second Datepicker’s icon to open its picker
  • Click back on the first Datepicker’s icon

You’ll now see that each component displays the correct selected value, with no cross-contamination between the two.

内容的提问来源于stack exchange,提问作者Renato Carvalho

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 21:37:30