2016-06-20 8 views
0

このコードはフィールド値をフォームから取得し、コンソールでデバッグするときに値が正しく渡されることを確認できます。しかし、余分なオブジェクトが私の最初の値で追加されたため、Meteorはサニタイズエラーを投げます...アイデアはありますか?継承されるテンプレートオブジェクトがメテオで墨塗りエラーをスローする

Template.sendInvitationModal.events({ 
'submit form': function submitForm(event, template) { 
    event.preventDefault(); 

    var firstName = template.find("[name='firstName']").value, 
     lastName = template.find("[name='lastName']").value, 
     email = template.find("[name='emailAddress']").value, 
     store = template.find("[name='store'] option:selected").value, 
     position = template.find("[name='position'] option:selected").value, 
     roles = template.find("[name='roles'] option:selected").value; 

    debugger; 

    if (email && roles && position !== "") { 
    Meteor.call("sendInvitation", { 
    firstName: firstName, 
    lastName: lastName, 
    email: email, 
    store: store, 
    position: position, 
    roles: roles 
    }, function (error, response) { 
    if (error) { 
     toastr["warning"](error.reason); 
    } else { 
     $("#send-invitation-modal").modal('hide'); 
     $('.modal-backdrop').hide(); 
     toastr["success"]("Invitation sent!"); 
    } 
    }); 
} else { 
    toastr["warning"]("Please set an email and at least one user type!"); 
}}}); 

これは "sendInvitation"

firstName = "Richard", template = B…e.TemplateInstance {view: B…e.View, data: Object, firstNode: div#send-invitation-modal.modal.fade.in, lastNode: div#send-invitation-modal.modal.fade.in, _allSubsReadyDep: T…r.Dependency…} 

を呼び出すときのfirstNameに渡される値であり、そして流星がサニタイズエラーがスローされます。助言がありますか?

答えて

0

フォームから取り出した値から変数の代入をオブジェクトに変換するだけで解決策を見つけることができました(御協力ありがとうございます)。それを解決!正しいコードは...

Template.sendInvitationModal.events({ 
'submit form': function submitForm(event, template) { 
    event.preventDefault(); 

    var data = { 
    firstName: template.find("[name='firstName']").value, 
    lastName: template.find("[name='lastName']").value, 
    email: template.find("[name='emailAddress']").value, 
    store: template.find("[name='store'] option:selected").value, 
    position: template.find("[name='position'] option:selected").value, 
    roles: template.find("[name='roles'] option:selected").value 
    }; 

    if (data.email && data.roles && data.position !== "") { 
    Meteor.call("sendInvitation", data, function (error, response) { 
     if (error) { 
     toastr["warning"](error.reason); 
     } else { 
     $("#send-invitation-modal").modal('hide'); 
     $('.modal-backdrop').hide(); 
     toastr["success"]("Invitation sent!"); 
     } 
    }); 
    } else { 
    toastr["warning"]("Please set an email and at least one user type!"); 
    } 
} 
}); 
関連する問題