@jagi - with my subject and subject_lc example above, I want to implement these in afterSet, with a switch statement on my trigger fields (e.g. subject):
afterSet: function(event) {
switch (event.data.fieldName) {
case 'subject':
this.set('subject_lc', event.data.setValue.trim().toLowerCase());
break;
}
}
When create a new MyModel({subject: ' AAaa '});
and then log out the document before calling .save()
on it, I see that the subject is set, but sub ject_lc isnt':
{
_modifiers: {
'$set': {
subject_lc: 'aaaa'
}
},
_errors: { /* ... */ },
_id: null,
subject: ' AAaa ',
subject_lc: null,
_isNew: true
}
How can I have these fields saved when I first create a new model?
methods: {
makeWinner() {
this.winner = true;
},
@maco144 I believe you would be better off using this.set('winner', true);
and you would also have to call this.save()
in your method. that said, I would personally make sure that this is run inside a server-side Meteor method:
```
Meteor.methods({
setPlayerWinner: function(playerId) {
// Perform checks on this.userId ? Security for who can set winner etc.
var player = Player.findOne(
Meteor.methods({
setPlayerWinner: function(playerId) {
// Perform checks on this.userId ? Security for who can set winner etc.
var player = Player.findOne(playerId);
player.set('winner', true);
player.save();
return player;
});
const c = new Color({R: -3, G: 0, B: 255}); valid = c.validate();