비밀번호를 제어하고 javascript의 도움으로 일치하는 비밀번호 필드를 확인하기 위해 ember 컨트롤로 javascript 코드를 작성하고 싶습니다. emberjs와 함께 할 수 있으면 알려주세요.이 코드를 사용해 보았습니다.ember js (비밀번호는 emberjs와 일치하는 비밀번호 확인 비밀번호 확인)
http://jsfiddle.net/8MRcS/12/
내가 그 wokring보다 app.js 컨트롤러에 넣고 경우 그것의 가입 컨트롤에서 완벽하게 작동하지 않는 것보다 내 CONTORL에서이 코드를 넣어하지만 난 가입 코드 내에서이 필요로 할 때 나도 몰라.
여기 내 템플릿 코드입니다.
<script type="text/x-handlebars" data-template-name="signup">
<h2>Sign Up</h2>
{{outlet}}
<form {{action "submit" on="submit" }}>
<!-- //This connects to the controller, using the user object -->
<p><label>Name: {{input type="text" value=user.name required="true"}}</label></p>
<p><label>Username: {{input type="text" value=user.username required="true"}}</label></p>
<p><label>Password: {{input value=user.password type="password" id="password" required="true"}}</label></p>
<p><label>Confirm Password: {{input value=user.confirm type="password" id="confirm" required="true"}}</label></p>
</br>
<p><label>Email: {{input type="email" value=user.email required="true"}}</label></p>
<p><label>Address: {{input type="text" value=user.address required="true"}}</label></p>
<p><label>Age: {{input type="number" value=user.age required="true"}}</label></p>
<button id="submit" {{bind-attr disabled="cannot_submit"}}>Submit form</button>
<button {{action "clear"}}>Clear</button>
<p></p>
<button> {{#link-to 'login'}}Already member{{/link-to}}</button>
</form>
{{message}}
</script>
가입 컨트롤러 코드.
App.SignupController = Ember.ObjectController.extend({
// User is the model used for binding the view and the controller
// If you look at the view, you will see user.username, and user.password being
// used as input values
// BTW this is a JavaScript object, (i.e in JSON)
user: {
//These values are just place holders for the moment
name: "",
username: "",
email: "",
address: "",
age: "",
password: "",
confirm: "",
},
// The functions called when and event is triggered from the view (i.e button click)
actions: {
// Action called when form is submitted, refer to form action attribute in view
submit: function() {
var self = this;
var submitUser = {};
submitUser.name = self.user.name;
submitUser.username = self.user.username;
submitUser.password = self.user.password;
submitUser.cpassword = self.user.confirm;
submitUser.email = self.user.email;
submitUser.address = self.user.address;
submitUser.age = self.user.age;
// This is the API call to the web services, it uses the user (this.user) to send
// the login info, and recives either the logged in user info, or an error
console.debug(this.user);
console.debug(this.submitUser);
$.post("http://herukoapp.com/users", JSON.stringify(this.user), function(data,status){
data = JSON.parse(data);
console.debug(data);
});
},
// Called when the clear button is clicked, see button tag in view
clear: function() {
this.set('user.name', "");
this.set('user.username', "");
this.set('user.password', "");
this.set('user.confirm', "");
this.set('user.email', "");
this.set('user.address', "");
this.set('user.age', "");
}
},
});
내가 암호 일치 할 것입니다 귀하의 SignupController에서 아무 것도 볼니까. ApplicationController에 이것을 남겼습니까? – tikotzky