admin管理员组文章数量:1332896
I have two template forms in a page one for "Log In" and another "Sign Up". Understood to use Accounts
package from documentation. But could not figure out how to toggle between these two forms when user clicks on "Log In" link or "Sign Up" link?
Code:
<body>
<div class="blog-masthead">
<div class="container">
<nav class="blog-nav">
<a class="blog-nav-item" href="#">Home</a>
<a class="blog-nav-item active" href="#">Login</a>
<a class="blog-nav-item active" href="#">Sign Up</a>
<a class="blog-nav-item" href="#">About</a>
</nav>
</div>
</div>
{{> signInForm}}
</body>
<template name="signInForm">
<div class="container">
<form class="form-signin" role="form" id="signInForm">
<h2 class="form-signin-heading">Please Log in</h2>
<input type="email" class="form-control" placeholder="Email address" required="" autofocus="" id="login-email">
<input type="password" class="form-control" placeholder="Password" required="" id="login-password">
<div class="row">
<label class="remember-me">
<input type="checkbox" name="remember-me" value="remember-me" id="remember-me" > Remember me
</label>
<a href="#" class="pull-right">Forgot Password</a>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Log in</button>
<p class="text-left">First time user? <a href="#">Register</a></p>
</form>
</div>
</template>
<template name="signUpForm">
<div class="container">
<form class="form-signin" role="form" id="signUpForm">
<h2 class="form-signin-heading">Please sign up</h2>
<input type="text" class="form-control" placeholder="Name" required="" autofocus="" id="signup-name">
<input type="email" class="form-control" placeholder="Email address" required="" autofocus="" id="signup-email">
<input type="password" class="form-control" placeholder="Password" required="" id="signup-password">
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign Up</button>
<p class="text-left">Already have account? <a href="#">Login</a></p>
</form>
</div>
I have two template forms in a page one for "Log In" and another "Sign Up". Understood to use Accounts
package from documentation. But could not figure out how to toggle between these two forms when user clicks on "Log In" link or "Sign Up" link?
Code:
<body>
<div class="blog-masthead">
<div class="container">
<nav class="blog-nav">
<a class="blog-nav-item" href="#">Home</a>
<a class="blog-nav-item active" href="#">Login</a>
<a class="blog-nav-item active" href="#">Sign Up</a>
<a class="blog-nav-item" href="#">About</a>
</nav>
</div>
</div>
{{> signInForm}}
</body>
<template name="signInForm">
<div class="container">
<form class="form-signin" role="form" id="signInForm">
<h2 class="form-signin-heading">Please Log in</h2>
<input type="email" class="form-control" placeholder="Email address" required="" autofocus="" id="login-email">
<input type="password" class="form-control" placeholder="Password" required="" id="login-password">
<div class="row">
<label class="remember-me">
<input type="checkbox" name="remember-me" value="remember-me" id="remember-me" > Remember me
</label>
<a href="#" class="pull-right">Forgot Password</a>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Log in</button>
<p class="text-left">First time user? <a href="#">Register</a></p>
</form>
</div>
</template>
<template name="signUpForm">
<div class="container">
<form class="form-signin" role="form" id="signUpForm">
<h2 class="form-signin-heading">Please sign up</h2>
<input type="text" class="form-control" placeholder="Name" required="" autofocus="" id="signup-name">
<input type="email" class="form-control" placeholder="Email address" required="" autofocus="" id="signup-email">
<input type="password" class="form-control" placeholder="Password" required="" id="signup-password">
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign Up</button>
<p class="text-left">Already have account? <a href="#">Login</a></p>
</form>
</div>
Share
Improve this question
asked Aug 17, 2014 at 2:03
Himanshu YadavHimanshu Yadav
13.6k49 gold badges170 silver badges295 bronze badges
1 Answer
Reset to default 7Well, if you want to do it "The Meteor Way" there are two basic options and you need to decide which suits your need best:
a. you can inject the template you want to use to a placeholder using UI.insert and UI.render (or UI.renderWithData if you need data to be rendered, example:
UI.insert(UI.render(Template.name), document.body)
UI.insert(UI.renderWithData(Template.foo, {bar: "baz"}), document.body)
b: you can use Session based conditions in your template and order it to appear only when a certain Session is set, example:
<template name="signInForm">
<div class="signUp"> click me to make the sign up form appear</div>
<div class="container">
{{#with userPressedSignUp}}
<form class="form-signin" role="form" id="signUpForm">
.. form elements..
</form>
{{/with}
</template>
Template.signInForm.userPressedSignUp = ->
return Session.get 'signUp-visible"
Template.signInForm.events
'click .signUp': (event) ->
Session.set 'signUp-visible', true
Session.set 'signUp_visible', false
# The template will not show the contents of the "with" as long as the session
# variable is 'false', change it by clicking on "signUp" div when you want the form to appear
本文标签: javascriptGetting started with Meteor ShowHide Templates on clickStack Overflow
版权声明:本文标题:javascript - Getting started with Meteor: ShowHide Templates on click - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742298161a2449143.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论