Hi!
I have an application that should highlight some certain HTML fields red if they’re “erroneous”. These fields coincide with documents from a subscription. I figured it’d make most sense to apply this changing of CSS on the fields in onRendered (as it’s a simple DOM manipulation that’s done once the template has already been created). I think the problem with this is that onRendered wouldn’t necessarily have access to my subscribed document in MiniMongo and thus wouldn’t be able to apply the css.
Here’s some stuff I’ve been trying. The template example is called “Object” and I’ll be subscribing and working on “Objects”
import { Objects } from …
//Simple onCreated where I’m subscribing to Objects
Template.Object.onCreated(function () {
var self = this;
self.autorun(function () {
self.objectSubscription = Meteor.subscribe(‘Object’, {
onReady: function () {
},
});
}
});
//onRendered where I try to change the css of an Object in MiniMongo
Template.Object.onRendered(function () {
const obj = Objects.findOne({someWhereClause});
if (obj.isErroneous) {
$(’#objID’).addClass(‘error’);
}
}
The problem is that onRendered does not see anything in my MiniMongo collection and thus cannot find an Object and set its style. I’m confused as to how this is possible though, because the subscription already gets completed in onCreated. I’m using the MiniMongo explorer and not seeing anything in my Objects explorer after onCreated. However, I’m seeing it if I subscribe in onRendered (but I can’t do this because it leads to redundant subscriptions and is not an appropriate place to put it)