ext当表单中的输入项为必填时,输入项label后显示红色的*

form表单里,当输入项为必填项时,需要将对应item的allowblank属性设置为true,如果item的label后面自带红色的*,表单中哪些输入项是“必填”,哪些输入项是“非必填”,一眼望去清晰明了,对用户来说会更加友好。

将下面的代码,放在页面js代码中Ext.onReady的前面,页面里的必填项的label后面会自带红色的*

代码如下:

/*
 重写allowBank的属性配置
 */
Ext.override(Ext.form.field.Base, {
    initComponent: function () {
        if (this.allowBlank !== undefined && !this.allowBlank) {
            if (this.fieldLabel) {
                this.fieldLabel += '<font color=red>*</font>';
            }
        }
        this.callParent(arguments);
    }
});

 效果图:

原文地址:https://www.cnblogs.com/daihu/p/10167094.html