I use check() method to filter the character inputs in my form fields. to check if only string is inputted in the name text field.
i already include the check package using meteor add check
in command prompt. and also use import { check } from 'meteor/check';
to my Meteor method file. but still its not working. client can still input any character to the text field and received by the database
here is the codes:
body.js
Template.addPlayerForm.events({
'submit form': function(event){
event.preventDefault();
var playerNameVar = event.target.playerName.value;
var playerScore = event.target.setScore.value;
if(playerNameVar!=""){
Meteor.call('createPlayer', playerNameVar, playerScore);
event.target.playerName.value = "";
event.target.setScore.value = "";
}
}
});
players.js
import {Monggo} from 'meteor/mongo';
import { check } from 'meteor/check';
export const PlayersList = new Mongo.Collection('players');
Meteor.methods({
'createPlayer': function(playerNameVar,playerScore){
check(playerNameVar, String);
var currentUserId = Meteor.userId();
if(currentUserId){
check(playerNameVar, String);
PlayersList.insert({
name: playerNameVar,
score: playerScore ? playerScore : 0,
createdBy: currentUserId
});
}
}
});
Thanks in advance