PDA

View Full Version : How to set defaults for every form in my application



TheNakedPirate
26 Nov 2007, 5:01 PM
I find my self adding this to every form I make

Is there a way to set these ONCE in one spot at the beginning of the script to save time/money/effort.




, border: false
, labelPad: 10
, defaults: {
width: 180
}
, layoutConfig: {
labelSeparator: ''
}

tryanDLS
26 Nov 2007, 5:17 PM
You could just extend FormPanel and set those properties in the ctor.

TheNakedPirate
26 Nov 2007, 5:25 PM
I thought about that but I was hoping that there was a way of just setting them through a prototype or even something like Ext.BLANK_IMAGE_URL so I wouldn't have to do an extend on every form I make.

I just don't have the skill to work out how to do it yet :((

tryanDLS
26 Nov 2007, 5:42 PM
You don't have to extend every time you use - do it once and then instantiate that class instead of FormPanel. This is no different than the way Ext extends FormPanel from BaseForm and all the way up to Component.

You could do this via the prototype, but you'd have to look at every one of the configs and see how they're used in the source. Simple ones can be added to the prototype, but some of the others may need different handling (e.g. defaults and layoutconfig)

The 1st option is probably cleaner and once you understand the pattern, you can implement it wherever you need. I think there is also a tutorial on extending classes.

TheNakedPirate
26 Nov 2007, 5:57 PM
actually it turns out i do have the skill :)

This seems to do the job


Ext.form.FormPanel.prototype.border = false;

TheNakedPirate
26 Nov 2007, 5:58 PM
You don't have to extend every time you use - do it once and then instantiate that class instead of FormPanel. This is no different than the way Ext extends FormPanel from BaseForm and all the way up to Component.

You could do this via the prototype, but you'd have to look at every one of the configs and see how they're used in the source. Simple ones can be added to the prototype, but some of the others may need different handling (e.g. defaults and layoutconfig)

The 1st option is probably cleaner and once you understand the pattern, you can implement it wherever you need. I think there is also a tutorial on extending classes.

Thanks, I do understand what you are saying but the prototype way suits me for now.

hendricd
26 Nov 2007, 7:43 PM
Have you tried it yet with all of 'em?


Ext.apply(Ext.form.FormPanel.prototype,

{ border: false
, labelPad: 10
, defaults: {
width: 180
}
, layoutConfig: {
labelSeparator: ''
}
});I'd be a little concerned about the possible layoutconfig and default clashes of the future (if this is going to effect all class instances)

Cool way of dealing with it tho B)