Dig4Fire
26 Sep 2009, 7:40 AM
Hello,
this is my first plugin. Its very simple. It marks required form fields (allowBlank: false) with asterisk and add hint under the form. Any comments are welcome.
16554
Ext.ns("Ext.ux", "Ext");
Ext.ux.AllowBlank = Ext.extend(Object, {
/**
* @param String
*/
asteriskColor: '#8B0000',
/**
* @param Boolean
*/
hint: true,
/**
* @param String
*/
hintText: 'Required fields',
/**
* @param String
*/
hintCls: '',
/**
* @param String
*/
hintStyle: 'font-family: tahoma,arial,helvetica,sans-serif; font-size: 12px; margin-top: 20px;',
/**
* constructor
* @param config
*/
constructor: function(config) {
config = config || {};
Ext.apply(this, config);
},
init: function(form) {
var requiredFields = false;
var color = this.asteriskColor;
var separator;
Ext.each(form.find(), function (item) {
if (item.allowBlank === false) {
if (item.labelSeparator) {
separator = item.labelSeparator;
} else if (form.defaults.labelSeparator) {
separator = form.defaults.labelSeparator;
} else {
separator = ':';
}
item.labelSeparator = '<span style="color:'+color+';">*</span>'+separator;
requiredFields = true;
}
});
if (requiredFields && this.hint){
form.add({
xtype: 'box',
anchor: '100%',
autoEl:{
tag:'div',
html: '<span style="color:'+color+';">*</span> '+this.hintText,
style: this.hintStyle,
cls: this.hintCls
}
});
}
}
});
Ext.preg('AllowBlank', Ext.ux.AllowBlank);
this is my first plugin. Its very simple. It marks required form fields (allowBlank: false) with asterisk and add hint under the form. Any comments are welcome.
16554
Ext.ns("Ext.ux", "Ext");
Ext.ux.AllowBlank = Ext.extend(Object, {
/**
* @param String
*/
asteriskColor: '#8B0000',
/**
* @param Boolean
*/
hint: true,
/**
* @param String
*/
hintText: 'Required fields',
/**
* @param String
*/
hintCls: '',
/**
* @param String
*/
hintStyle: 'font-family: tahoma,arial,helvetica,sans-serif; font-size: 12px; margin-top: 20px;',
/**
* constructor
* @param config
*/
constructor: function(config) {
config = config || {};
Ext.apply(this, config);
},
init: function(form) {
var requiredFields = false;
var color = this.asteriskColor;
var separator;
Ext.each(form.find(), function (item) {
if (item.allowBlank === false) {
if (item.labelSeparator) {
separator = item.labelSeparator;
} else if (form.defaults.labelSeparator) {
separator = form.defaults.labelSeparator;
} else {
separator = ':';
}
item.labelSeparator = '<span style="color:'+color+';">*</span>'+separator;
requiredFields = true;
}
});
if (requiredFields && this.hint){
form.add({
xtype: 'box',
anchor: '100%',
autoEl:{
tag:'div',
html: '<span style="color:'+color+';">*</span> '+this.hintText,
style: this.hintStyle,
cls: this.hintCls
}
});
}
}
});
Ext.preg('AllowBlank', Ext.ux.AllowBlank);