PDA

View Full Version : Writing custom MessageTargets



extcoder007
28 Jan 2012, 5:35 AM
Hello Friends,

I have an requirement in which error message needs to appear above the Form field elements as shown in the image. The predefined messagetarget (qtip ,title ,under , side) not supported for my requirement.

Note: error message should occupy entire width of label + component. This behavior is expected across all the formpanel in my application.

any suggestions ???

31115--Thanks

findajit
28 Jan 2012, 9:04 PM
Look at the Ext.form.FieldContainer class.

Raja Murugesan
30 Jan 2012, 9:58 AM
Include the following code into your application, in required form fields add msgTaget config as 'customeTarget' .



Ext.apply(Ext.form.MessageTargets, {
'customTarget':{
mark: function(field, msg){
field.el.addClass(field.invalidClass);
if (!field.errorEl) {
var elp=field.getItemCt();
if (!elp) {
field.el.dom.title = msg;
return;
}
field.errorEl=elp.insertFirst({
cls : 'x-form-invalid-msg'
});
field.on('resize', field.alignErrorEl, field);
field.on('destroy', function() {
Ext.destroy(this.errorEl);
}, field);
}
field.alignErrorEl();
field.errorEl.update(msg);
Ext.form.Field.msgFx[field.msgFx]
.show(field.errorEl, field);
},
clear: function(field){
field.el.removeClass(field.invalidClass);
if (field.errorEl) {
Ext.form.Field.msgFx[field.msgFx].hide(field.errorEl,
field);
} else {
field.el.dom.title = '';
}
}
}

});


Hope this helps....

extcoder007
30 Jan 2012, 11:35 AM
Thanks Raja....