In my page (html form) I have 2 options (radio buttons). Based on the selection of the user I want to show different input fields. Here are my templates.
<template name="main">
<div class="radio">
<label>
<input id="radio1" name="optiontype" type="radio" value="1"> Option1
</label>
</div>
<div class="radio">
<label>
<input id="radio2" name="optiontype" type="radio" value="2"> Option1
</label>
</div>
<div>
{{ > optionTemplate }}
</div>
</template>
Here is my option template
<template name="optionTemplate">
{{#if option1}}
<div class="form-group">
<input type="text" class="form-control" placeholder="enter option1">
</div>
<div class="form-group">
<input type="text" class="form-control =" placeholder="enter option1">
</div>
{{/if}}
{{#if option2}}
<div class="form-group">
<input type="text" class="form-control =" placeholder="enter option2">
</div>
{{/if}}
</template>
In my main.js file I have the following code
Template.main.events({
"click #radio1" : function(event, template) {
Template.optionTemplate.option1 = function(){
return true;
}
},
"click #radio2" : function (event, template) {
Template.optionTemplate.option2 = function(){
return true;
}
}
});
Now what is happening is that when I place
Template.optionTemplate.option1 = function(){
return true;
}
outside the Template.main.events then the HTML within the "option if block" appears but obviously thats not what I want, but when place it inside Template.main.events({...}) then nothing happens. What I want is dynamic insertion of HTML based on user selection. I would really appreciate if someone can clarify why is this happening and what is the solution for this. Thanks.