Hi,
I have this sample code that calculated age based on birthdate input using autoform:
temaplate:
<head>
<title>Calculate age</title>
</head>
<body>
{{> form}}
</body>
<template name="form">
{{> quickForm fields='birthdate,myAge' collection="Age" id="insertAgeForm" type='insert' buttonContent="Calculate Age"}}
</template>
Schema:
Age = new Meteor.Collection("age");
Age.attachSchema(new SimpleSchema ({
birthdate: {
type: Date,
label: "Birthday",
optional: true,
autoform: {
type: 'bootstrap-datepicker'
}
},
myAge: {
type: Number,
label: "My Age",
optional: true,
},
ageCompute: {
type: Number,
optional: false,
decimal: true,
autoValue:function(){
var dayBirth = this.siblingField("birthdate").value;
var age =moment().diff(moment(dayBirth, 'MM/DD/YYYY'), 'years');
console.log(age);
return age;
}
}
}));
The function is working on the console but I don’t know the approach on how to pass the value to the sibling field myAge
.
What is the best way to reactively pass the value of the age function to the sibling field?
For example when the user pick the date of his birthday on the datepicker, it reactively pass the value to myAge
field without triggering an event, in this way, the user will see his age immediately.
Any help will greatly appreciate!
Thanks,