2012/05/09

[ExtJS 4.1] Mark a red Asterisk/Star on an Required Fields

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>';
}
}
}
});

2 則留言:

4種PDF轉Word的免費方法(pdf to word, pdf to doc, pdf2word, pdf2doc)

本文將介紹4種 將PDF轉Word檔 的方法,分別分析其效能、方便性、精確性等指標。 1. nitropdf提供的線上 Convert PDF to Word (DOC) 這是一個 線上免費PDF轉Word檔 的服務,網址: http://www.pdftoword.com...