meteor - How to pass login callback to form error in Meteorite with Mesosphere? -
i using mesosphere form package own custom login page. heres login form:
mesosphere({ name: "loginform", method: "login", fields: { usernameemail: { required: true, format: /^[a-za-z0-9_]{2,25}$/i, message: "only alphanumeric usernames", transform:["trim"] }, password: { required: true, message: "6-25 characters please", rules:{ maxlength:25, minlength:6 } } } });
once validate object, want make sure this user login information valid, if not pass information rendered error.
meteor.methods({ login: function (rawformdata) { var validationobject = mesosphere.loginform.validate(rawformdata); console.log("logging in..."); if (!validationobject.errors) { meteor.loginwithpassword(validationobject.formdata.usernameoremail, validationobject.formdata.password, function (err) { if (err) { //user doesnt exit console.log("user doesnt exist"); } else { //user logged in... console.log("logged in"); } } ); } else { console.log("errors:" + json.stringify(validationobject.errors)); } },
i want specify username-error or password-error show up.
<template name="login"> log in please <form name="loginform"> <p><input type="text" name="usernameoremail" placeholder="username or email"/></p> <span id="usernameoremail-error"></span> <p><input type="password" name="password" placeholder="password"/></p> <span id="password-error"></span> <input type="submit" value="login"> or <a href="{{pathfor 'signup'}}">sign up</a> </form>
clarification:
i want able implement additional validation step on either client or server. on client, i'd able check if given login credentials valid (on client). if creating new user, i'd able check user username doesnt exist (on server).
clarification 2:
i understand can invoke function or method "method" element (https://github.com/copleykj/mesosphere#basics-elements) how can return success or error , how message handled?
you can override default error functionality onfailure callback. goes on same level of fields inside object. https://github.com/copleykj/mesosphere/blob/master/readme.md#error-management
Comments
Post a Comment