-
15 Oct 2007 4:40 AM #1
FormLayout : Prefix/Suffix to form fields
FormLayout : Prefix/Suffix to form fields
Juste a modification of FormLayout to have suffix and/or prefix on fields.
Ex :
[PHP]new Ext.form.FormPanel({
...,
items : [{
xtype : 'fieldset',
name : 'price',
fieldLabel : 'Price',
suffix : '
-
2 Apr 2009 6:16 PM #2
for some strange reason vBulletin erased practically all of @tof's code.
i'm reposting what i copied from the post, plus a fix by @condor, plus some custom-added stuff to display an asterisk for allowBlank:false fields (in a <span> tag with a class of "x-form-field-asterisk" -- add your own custom CSS to style it):
Code:Ext.override(Ext.layout.FormLayout, { // enable Field prefix / suffix (additional text before/after the input element) // by @tof -- http://extjs.com/forum/showthread.php?t=15252 renderItem : function(c, position, target) { if (c && !c.rendered && c.isFormField && c.inputType != 'hidden') { var args = [ c.id, c.fieldLabel + (c.allowBlank? '' : '<span class="x-form-field-asterisk"> * </span>'), // bugfix for "FormLayout labelStyle breaks hideLabels, labelAlign and labelWidth" // by @condor -- http://www.extjs.com/forum/showthread.php?p=228652#post228652 (this.labelStyle || '') + ';' + (c.labelStyle || ''), this.elementStyle || '', typeof c.labelSeparator == 'undefined' ? this.labelSeparator : c.labelSeparator, (c.itemCls || this.container.itemCls || '') + (c.hideLabel ? ' x-hide-label' : ''), c.clearCls || 'x-form-clear-left' ]; if (typeof position == 'number') { position = target.dom.childNodes[position] || null; } if (position) { this.fieldTpl.insertBefore(position, args); } else { this.fieldTpl.append(target, args); } var newEl, fEl = Ext.get('x-form-el-' + c.id); c.render(fEl); if (c.prefix) { // Field prefix if (c.isXType('trigger')) { newEl = c.wrap.insertHtml('afterBegin', '<span>' + c.prefix + ' </span>', true); c.el.setWidth(c.el.getWidth() - c.trigger.getWidth() - newEl.getWidth()); } else { newEl = fEl.insertHtml('afterBegin', '<span>' + c.prefix + ' </span>', true); c.el.setWidth(c.el.getWidth() - newEl.getWidth()); } } if (c.suffix) { // custom field suffix addition by @tof if (c.isXType('trigger')) { newEl = c.wrap.insertHtml('beforeEnd', '<span> ' + c.suffix + '</span>', true); c.el.setWidth(c.el.getWidth() - c.trigger.getWidth() - newEl.getWidth()); } else { newEl = fEl.insertHtml('beforeEnd', '<span> ' + c.suffix + '</span>', true); c.el.setWidth(c.el.getWidth() - newEl.getWidth()); } } } else { Ext.layout.FormLayout.superclass.renderItem.apply(this, arguments); } } });
Sencha Docs / Ext 3.x - ( Docs | Examples )
Learning Center / Saki's Examples (for 2.x) / HOWTO - ( Report Bugs | Post Proper Code )
-
2 Jun 2009 10:48 PM #3
I'd like to inquire how such modifications affect ExtJS update process? For example if I want to update ExtJS library to the next version, not major but minor, what is the probability that such fix will be broken?
Thank you!
-
2 Jun 2009 11:52 PM #4
Sencha Docs / Ext 3.x - ( Docs | Examples )
Learning Center / Saki's Examples (for 2.x) / HOWTO - ( Report Bugs | Post Proper Code )
-
5 Jun 2009 10:49 PM #5
FormLayout Prefix/Suffix to form fields
FormLayout Prefix/Suffix to form fields
suffix_array is nil. What method is that code in and in what class? There are so many scripts in your game, one of them is probably calling that method before the prefix/suffix script expects it to be called.
-
6 Jun 2009 7:01 AM #6
Spammers eh?
Weird little people. Who knows what goes on in their tiny minds?Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
8 Dec 2009 11:07 AM #7
Label Alignments
Label Alignments
Hi Animal,
I need your help. I have a form with few fields in it. I want to set the labelAlign for certain fields like text areas. if it is TextArea the Label is on top of text Area. and if it is a regular text field they are normally side by side. only I want to change the alignment if it is a textarea in my form.
labelAlign:'top' is applying to whole form. if I put this
{
xtype: 'textarea',
name: 'txtUpdReason',
style: "background:#ededed;",
labelAlign: 'top',
readOnly: true,
height: 100,
width: 100,
labelAlign:'top',
anchor: '100%',
fieldLabel: 'Update Reasons'
}
No Effects.
-
8 Dec 2009 1:50 PM #8
Unfortunately, labelAlign is fixed at the Container level right now.
Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
8 Dec 2009 5:07 PM #9
-
14 Apr 2011 4:34 AM #10
In case anyone comes across this thread and discovers that the code above no longer works, here's an updated version for ExtJS 3.3.1:
I've only included the prefix, since that's all I needed, but it shouldn't be hard to add a suffix too.PHP Code:Ext.override(Ext.layout.FormLayout, {
renderItem : function(c, position, target) {
if(c && (c.isFormField || c.fieldLabel) && c.inputType != 'hidden'){
var args = this.getTemplateArgs(c);
if(Ext.isNumber(position)){
position = target.dom.childNodes[position] || null;
}
if(position){
c.itemCt = this.fieldTpl.insertBefore(position, args, true);
}else{
c.itemCt = this.fieldTpl.append(target, args, true);
}
if(!c.getItemCt){
Ext.apply(c, {
getItemCt: function(){
return c.itemCt;
},
customItemCt: true
});
}
c.label = c.getItemCt().child('label.x-form-item-label');
if(!c.rendered){
c.render('x-form-el-' + c.id);
/* start extra code */
var newEl,
fEl = Ext.fly('x-form-el-' + c.id);
if (c.prefix) { // Field prefix
if (c.isXType('trigger')) {
newEl = c.wrap.insertHtml('afterBegin', '<span>' + c.prefix + ' </span>', true);
c.el.setWidth(c.el.getWidth() - c.trigger.getWidth() - newEl.getWidth());
} else {
newEl = fEl.insertHtml('afterBegin', '<span>' + c.prefix + ' </span>', true);
c.el.setWidth(c.el.getWidth() - newEl.getWidth());
}
}
/* end extra code */
}else if(!this.isValidParent(c, target)){
Ext.fly('x-form-el-' + c.id).appendChild(c.getPositionEl());
}
if(this.trackLabels){
if(c.hidden){
this.onFieldHide(c);
}
c.on({
scope: this,
show: this.onFieldShow,
hide: this.onFieldHide
});
}
this.configureItem(c);
}else {
Ext.layout.FormLayout.superclass.renderItem.apply(this, arguments);
}
}
});
Last edited by adamvert; 14 Apr 2011 at 4:36 AM. Reason: code formatting


Reply With Quote

