cesco
September 5, 2015, 3:53pm
1
Hi
I have create this simple app to test login function.
This is the js code:
Template.Login.events({
‘submit #login ’: function(event, template) {
event.preventDefault();
var username = template.find(’#login-username ’).value,
password = template.find(’#login-password ’).value;
Meteor.loginWithPassword(username, password, function(error) {
if (!error) {
console.log('user');
}
else
{
template.find('#form-messages').html(error.reason);
console.log(error.reason);
}
return;
});
The link template.find create an error:
Exception in delivering result of invoking ‘login’:
I think it’s due to var “template” that can’t be invoke by loginWithPassword…
How i can fix it?
Thanks in advance
nxcong
September 5, 2015, 4:06pm
2
You try
var username = template.$('#login-username').val();
var password = template.$('#login-password').val();
if(username && password){
Meteor.loginWithPassword....
}
cesco
September 5, 2015, 4:22pm
3
thanks for the answer but problem is this line
template.find(’#form-messages ’).html(error.reason);
if i remove this everything works fine.
nxcong
September 5, 2015, 4:26pm
4
try{
template.find('#form-messages').html(error.reason);
}catch(ex){
console.error(ex)
}
what ex?
nxcong
September 5, 2015, 4:35pm
6
template.find(selector) return DOM element => template.find(’#form-message ’).innerHTML = error.reasoan.
or
tempalte.$(selector) return Jquery object => template.$(’#form-messages ’).html(error.reason);
cesco
September 5, 2015, 4:41pm
7
Ok that’s work, now i undestand. I have find a tutorial with that code. Is any difference about performance to use jQuery inside Meteor ?
Hello Cesco,
why are you using the template to get the form values anyways? The values can be fetched from the event Object like so for example:
var username = event.target.username.value;
var password = event.target.password.value;
I hope that helps.
cesco
September 5, 2015, 5:42pm
9
Thank you mikewink … nice tip!