简体   繁体   English

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

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

I need to add red asteriks to multiple form fields with the allowBlank property set as false in screens that extend the screen below.我需要在扩展下方屏幕的屏幕中将红色星号添加到多个表单字段,并将 allowBlank 属性设置为 false。 I've tried the solution here: ExtJS 4 - Mark a red asterisk on an required field but it isn't working.我已经尝试过这里的解决方案: ExtJS 4 - 在必填字段上标记一个红色星号,但它不起作用。 Is there some way I can add the functionality in the initComponent function?有什么方法可以在 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();
}
});

For adding this behavior to all your fields, you can override Ext.form.field.Base , for example:要将此行为添加到您的所有字段,您可以覆盖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