繁体   English   中英

如何在 Ext JS 文本字段标签中用星号标记必填字段

[英]How to mark required field with asterisk in Ext JS textfield labels

我需要在扩展下方屏幕的屏幕中将红色星号添加到多个表单字段,并将 allowBlank 属性设置为 false。 我已经尝试过这里的解决方案: ExtJS 4 - 在必填字段上标记一个红色星号,但它不起作用。 有什么方法可以在 initComponent 函数中添加功能吗?

Ext.define('APP.view.ux.visual.screen.UxClassicScreen', {
extend: 'Ext.form.Panel',
alias: 'widget.uxclassicscreen',

config: {
    layout: 'vbox'
},

initComponent: function(){
    var viewModel = this.getViewModel(),
        controller = this.getController();
    if(viewModel != null && controller != null){
        viewModel.set('isKiosk', controller.isKiosk());
    }
    this.callParent();
}
});

要将此行为添加到您的所有字段,您可以覆盖Ext.form.field.Base ,例如:

Ext.define('MyApp.overrides.form.field.Base', {
    override: 'Ext.form.field.Base',

    initLabelable: function () {
        this.callParent(arguments);

        if (this.fieldLabel && this.allowBlank === false) {
            this.labelSeparator += '<span class="mandatory">*</span>';
        }
    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM