Reputation: 17626
I have around 20 fields in my template and depending on an event on the page (the user click on a button which do some verifications on the server who return updated values for these fields), I want to auto update these fields who all belong to the object user. I don't want to user jQuery to update individually each of these fields. Is there a way in meteor to AutoUpdate all the fields linked to an object in Meteor?
Example of my template:
<template name="userForm">
<label>First name</label>
<input type="text" class="form-control" name="first_name" placeholder="Your name" value="{{user.first_name}}">
<label>Last name</label>
<input type="text" class="form-control" name="last_name" placeholder="Your last name" value="{{user.last_name}}">
</template>
The fields are well initialized on the page load, using the helpers:
Template.userForm.helpers({
user: function(){
return { first_name: "John", last_name: "Doe" };
}
})
I want to update these fields in my template when in my code the object user is modified, such has:
user.first_name="Mark".
Upvotes: 0
Views: 254
Reputation: 21384
Yes, of course, that's exactly what meteor's liveHTML is for.
Session.setDefault('user', { first_name: "John", last_name: "Doe" });
Template.userForm.helpers({
user: function() {
return Session.get('user');
}
})
and to set:
Session.set('user', OBJECT_FROM_SERVER);
But if you are interacting with the server, then why not just use a collection?
Upvotes: 1