array_field.js
and object_field.js
set
array_field
, but with not much sucess. Acctually it did store something in the document for that field, but it looks broken :)
var gameDetails = ({
winning: $('#matchTeam').val(),
achieved: $('#matchAchieved').val(),
objective: $('#matchObjective').val()
});
var matchFormHook = {
onSuccess: function(insert,result){
if(result)
$('#generalModal').modal('hide');
}
}
AutoForm.addHooks('matchDetails', matchFormHook);
hi @jagi
I've got a quick question regarding calculated fields. I've got a schema, and we are implementing some server-side filtering, sorting and pagination. Because of this, we need to have a lower-case version of certain text fields. What would be your recommended method for this? My current thought is to populate e.g. subject_lc with beforeSave: function(e) { this.subject_lc = this.subject.trim().toLowerCase(); }
.
Is this the best way to go about this? Thanks!
@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();