ExtJS 4 - Mark a red asterisk on an required field

后端 未结 11 2307
长发绾君心
长发绾君心 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:32

    You can still override the layout component similar to extjs3 bun given that there is no fieldLayout, I've overriden Ext.layout.Layout. It's quite similar to molecule man's solution but it's more general. Working for fields used in other containers than forms.

    Ext.override(Ext.layout.Layout, {
        renderItem: function(item, target, position) {
          if (item && !item.rendered && item.isFieldLabelable && item.fieldLabel && item.allowBlank == false) {
            item.fieldLabel += ' *';
          }
          this.callOverridden(arguments);
        }
    });
    

    This is simpler than your solution but not necesarely better, se example also used in fieldsets here

提交回复
热议问题