藏經閣

一切有為法,如夢幻泡影,如露亦如電,應作如是觀。

Making a red asterisk on required fields makes your user realize they are not allowed to be blank by intuition. In ExtJS, you can specify fields which cannot be blank such as the following code.

            items : [ {     
                xtype : 'textfield',    
                fieldLabel : 'Name',
                allowBlank : false,               
            }, {
                xtype : 'numberfield',
                fieldLabel : 'Age'                  
            } ]

I found a patch working fine on ExtJS 4.07 to realize this requirement.

Ext.override(Ext.layout.Layout, {
    renderItem
: function(item, target, position) {
     
if (item && !item.rendered && item.isFieldLabelable && item.fieldLabel && item.allowBlank == false) {
        item
.fieldLabel += '<span class="req" style="color:red">*</span>';

     
}
     
this.callOverridden(arguments);
   
}
});

ExtJS 4.0 Mark a red Asterisk on an Required Field

Mark a red Asterisk on an Required Field on ExtJS 4.1

And I modify it a little bit to make it work in ExtJS 4.1 MVC application architecture as following.
this.control({
'field' : {
beforerender : function(thisField, eOpts) {
if (thisField && !thisField.rendered && thisField.isFieldLabelable && thisField.fieldLabel && thisField.allowBlank == false) {
thisField.fieldLabel += '<span class="req" style="color:red">*</span>';
}
}
}
});

如何在Blogger新增隨機文章

Blogger Hack - How to add a Random Post Gadget in Blogger)

 


2 意見

  1. city  

    thanks for sharing.

  2. 六翼天使的窝  

    Good, it does work.

張貼留言