Reputation: 3750
The (simplified) template below renders a form with two input fields, pre-filled based on the data context. The form can be opened for several different data contexts (though only one at a time), in which case I want all fields to be rerendered with the new data - which mostly happens.
<template name="form">
<input type="text" value="{{title}}">
<input type="text" value="{{start_value}}">
</template>
The problem arises when two data contexts have the same value for either field - e.g. it is very common for start_value
to be 0. In this case, the corresponding input field will not be rerendered when the data context switches. Perhaps an example is in order:
start_value = 0
start_value
from 0
to 12
start_value = 0
start_value
still says 12
This seems to happen for all (primitive) identical values. Using a helper to return the value changes nothing but does confirm that the helper is rerunning as expected.
I can work around this with an autorun-afterflush on the template instance to explicitly update the input fields, but is there a more idiomatic way to make Meteor rerender "unchanged" fields?
Here is working example (and by working I mean it shows what doesn't work).
Just create those two files in the client directory of a clean Meteor project and you should be able to observe the behavior. Items 1 and 2 have the save value
and so the second input field will not change when you switch between them even if you have altered it manually. Items 3 and 4 have the same title
and exhibit similar behavior.
Upvotes: 0
Views: 99
Reputation: 518
I'm not exactly sure if I'm answering your question but if your trying to clear a value after the user closes the form so it does not repopulate with that value on reopen, then you could use the onDestroyed function
to do any clean up you need, such as clearing a session which appears to be what you set when the form is opened.
Upvotes: 1