I'm trying to make a really simple BMI calculation app using ExtJS. So far I can have the user input their height and weight into number fields, calculate the BMI and display this to the console. However, I can not work out how to display this to the view.
I have tried binding the value, and using a panel but no luck. All that is displayed is {bmi}
.
Ideally I would like the bmi value to be displayed once they click the "Calculate" button function.
EDIT - I found a way to resolve it using Ext.Template. Is this a good solution though?
Code -
Ext.define('JamieApp.view.main.Main', {
extend: 'Ext.Panel',
xtype: 'mainview',
requires: [
'Ext.layout.Fit'
],
controller: 'main',
viewModel: 'main',
items: [{
xtype: 'fieldset',
title: 'Enter your details',
items: [{
xtype: 'numberfield',
label: 'Enter your height',
name: 'height',
minValue: 100,
maxValue: 210,
required: true,
requiredMessage: "Test msg",
itemId: 'height'
}, {
xtype: 'numberfield',
label: 'Enter your weight',
required: true,
minValue: 30,
maxValue: 150,
name: 'weight',
itemId: 'weight',
reference: 'test',
}]
}, {
xtype: 'button',
text: 'Calculate',
listeners: {
tap: function(){
var height = this.up('panel').down('#height').getValue();
var weight = this.up('panel').down('#weight').getValue();
var heightInMeters = height / 100;
bmi = weight / (heightInMeters * heightInMeters);
bmi = bmi.toFixed(2);
console.log(bmi);
var t = new Ext.Template("Result: {bmi}")
t.append(this.up('panel').down('#labelTest').el, {
bmi: bmi
})
}
}
}, {
xtype: 'label',
title: 'test',
tpl: 'Result: {bmi}',
itemId: 'labelTest'
}]
});