ExtJS 4 - Mark a red asterisk on an required field

后端 未结 11 2257
长发绾君心
长发绾君心 2020-12-08 08:24

I have this problem where I need to add a red asterisk beside a fieldLabel when a field is marked as \"required\" (or allowBlank: false)

In

11条回答
  •  执念已碎
    2020-12-08 08:55

    An approach that you might find more elegant is adding a css class to any field label that is marked with allowBlank=false and style your mandatory indicator in CSS.

    Ext.define('Ext.ux.form', {
    
        extend: 'Ext.form.Panel',
    
        listeners: {
            'beforeadd': function(){
                if (!field.allowBlank) {
                    field.labelClsExtra = 'x-required';
                }
            }
        }
    
    });
    

    You can then style your field label in CSS with an :after pseudo utility:

    .x-required:after {
        content: ' *';
        color: red;
        font-weight: bold;
    }
    

提交回复
热议问题