View Full Version : Showing Currency in a Form

18 Aug 2011, 6:53 AM
I'm trying to display the currency that a number field is in somewhere in my field. It can be before the textfield, after the label, or even in the textfield (but I know that breaks the HTML5 number field, so that's fine).

How would I go about either putting the currency symbol before the textfield or at the end of the label?

fields = {
xtype: 'fieldset',
items: [
name : 'amount',
label: 'Amount',
xtype: 'numberfield',
labelAlign: 'left',
labelWidth: '40%',
required: false

My model looks like this:

amountModel = Ext.regModel("app.models.Amount", {
fields: [
{name: "amount", type: "int"},
{name: "currencySymbol", type: "string"}

How do I either refer to the model's currencySymbol in the Label, or somehow display it to the left of the textfield?

18 Aug 2011, 7:12 AM
if you create your form after your currency store is loaded, you can retrieve the currencySymbol and add it to the label. for example:

load: function(store, array)){
symbol = array[0].data.currencySymbol; //get the symbol

... //code setting up formPanel and other goodies

//and you can use this like: label: 'Amount' + symbol,

... //rest of the code

I wouldn't advise putting the symbol in the textfield, though.

18 Aug 2011, 10:13 AM
Thanks for the speedy reply, I'll give that a try!