Hello,
I have a html form with the below input element allowing users to enter a number. What I need to accomplish is on entering a number (number key press) i need to collect the take a value and do some calculation and display the result reactively?
What meteor event is available for me to accomplish that? how do i capture the data? so that i can do the calculation and update the DOM
Template.myTemplateName.events({
'keyup #my-input-element': function(event) {
if (event.which >= 48 && event.which <= 57) {
var numberPressed = event.which - 48;
}
// Do whatever you want with numberPressed
// like set a Session value that is reflected in the DOM via a helper
var calculatedResult = numberPressed * 100;
Session.set('calculatedResult', calculatedResult);
});
}
And in the accompanying html file you would have something like:
<template name="myTemplateName'>
<input type="text" id="my-input-element" />
Last number typed times 100: {{calculatedResult}}
</template>
Hey! There’s an interesting package - manuel:viewmodel - which might be helpful for more complex cases. Take a look at examples here: http://viewmodel.meteor.com
I haven’t used it yet, and would love to hear other fellows’ thoughts on pros & cons of such approach.