【问题标题】:ExtJS how to create a custom field from a custom componentExtJS 如何从自定义组件创建自定义字段
【发布时间】:2014-07-29 17:00:26
【问题描述】:

我有我的应用程序 (ExtJS 4.2.1) 并且我有一个表单:

xtype: 'form',
    bodyPadding: 10,
    autoScroll: false,
    itemId: 'editForm',
    defaults: { 
        msgTarget: 'side',
        xtype: 'textfield'
    },
    //layout:'anchor',
    items: [{
            xtype: 'combobox',
            itemId: 'cboEmployer',
            store: Ext.create('App.store.catalog.Employer', {
                autoLoad: true
            }),
            displayField: 'Description',
            valueField: 'EmployerId',
            fieldLabel: 'Company',
            name: 'EmployerId',
            queryMode: 'local',
            allowBlank: false,
        },{
            xtype: 'radiogroup',
            fieldLabel: 'Type',
            name: 'RequestInAdvance',
            columns: 2,
            items: [{
                    boxLabel: 'Normal',
                    name: 'RequestInAdvance',
                    inputValue: 0,
                    checked: true
                }, {
                    boxLabel: 'Advanced',
                    name: 'RequestInAdvance',
                    inputValue: 1
                }

            ]
        }, {

            xtype: 'fieldset',
            title: 'Date selection',
            defaults: {
                labelWidth: 89,
                anchor: '100%',
                layout: {
                    type: 'hbox',
                    defaultMargins: {
                        top: 0,
                        right: 5,
                        bottom: 0,
                        left: 0
                    }
                }
            },
            items: [{
                xtype: 'highlightdate', // <- This is a custom datepicker but I need it to be a field type
                name: 'SelectedDates',
                itemId: 'datePicker'
            }],

        },

    ],
    buttons: [{
        text: 'Save',
        action: 'commit',
        glyph: Glyphs.SAVE,
        disabled: true
    }],

xtype: 'highlightdate' 是一个自定义日期选择器,我需要进行自定义表单验证,以便将元素标记为错误:

在我的验证方法中,我有:

    var fieldMatch = Ext.ComponentQuery.query('field[name=' + error.field + ']');
 if (fieldMatch.length) {
                // add extra validaiton message to the offending field
                fieldMatch[0].markInvalid(error.message);
            }

所以当我尝试为我的highlightdate xtype 设置错误时,可以发现它不是field。

有没有办法解决这个问题?

【问题讨论】:

  • 这里已经有一个广泛的discussion on that topic,希望它对您的情况有所帮助。
  • highlightdate 组件从何而来?
  • 它是一个继承自 Date.Picker 的类。

标签: extjs extjs4 extjs4.1 extjs4.2 extjs-mvc


【解决方案1】:

xtype 只是自定义“highlightdate”类的简称,可以用new Namespace.CustomClass({cfg}) 表示法代替。你需要弄清楚的是:这个自定义类扩展了什么基类?如果它扩展 Ext.form.field.Base 或 Ext.form.field.Text 为 ex。而不是它也是一个字段并继承它的所有属性。

【讨论】:

  • 这个基类扩展:'Ext.picker.Date'
  • 所以我不知道我是否可以在类中添加一些东西,这样它也可以从 Ext.form.field.Base 扩展。或者也许我不能将这个组件既作为组件又作为字段。因此,我必须创建相同的组件,但从字段扩展。
  • Ext.picker.Date extends Ext.Component 所以你不能把它当作一个字段。然而,它包含一系列允许您更改 CSS 的方法(addCls、removeCls、...),因此您必须使用这些方法及其事件。
  • 哦,有趣,非常有趣。所以继承自 Ext.component 的东西不能被视为一个字段。
  • 也许您应该尝试使用Ext.form.field.Date 作为基类并从那里开始工作?
猜你喜欢
  • 2011-09-03
  • 2021-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-13
  • 2015-01-11
  • 1970-01-01
相关资源
最近更新 更多