Skip to content

Commit

Permalink
Login form - route configuration, fields validation, template
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel.faderski committed Feb 27, 2017
1 parent 4b5e50e commit 9a9a766
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
38 changes: 38 additions & 0 deletions openchat/app/components/login-form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Ember from 'ember';
import {TextInput, MinLength} from '../utils/text-input'

export default Ember.Component.extend({
username: TextInput.create({
value: '',
validators: [
new MinLength(1)
]
}),

password: TextInput.create({
value: '',
validators: [
new MinLength(1)
]
}),

init() {
this._super(...arguments);
let username = this.get('username');
let password = this.get('password');
this.nonFieldErrors = null;
},

showUsernameErrors: Ember.computed('username.{pristine,errors}', function () {
return !this.get('username.pristine') && this.get('username.errors');
}),

showPasswordErrors: Ember.computed('password.{pristine,errors}', function () {
return !this.get('password.pristine') && this.get('password.errors');
}),

formInvalid: Ember.computed('showUsernameErrors','showPasswordErrors', function () {
return this.get('showUsernameErrors') || this.get('showPasswordErrors');
})

});
1 change: 1 addition & 0 deletions openchat/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Router = Ember.Router.extend({

Router.map(function() {
this.route('register');
this.route('login');
this.route('error');
});

Expand Down
4 changes: 4 additions & 0 deletions openchat/app/routes/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Ember from 'ember';

export default Ember.Route.extend({
});
26 changes: 26 additions & 0 deletions openchat/app/templates/components/login-form.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<form>
<div>
<label for="username">Username</label>
{{ input type="text" value=username.value id="username" class="form-control"
name="username" aria-describedby="usernameHelpBlock" }}

{{#if showUsernameErrors}}
<div class="alert alert-danger">
This field is required
</div>
{{/if}}
</div>

<div>
<label for="password">Password</label>
{{ input type="password" value=password.value id="password" class="form-control"
name="password" aria-describedby="passwordHelpBlock" }}
{{# if showPasswordErrors }}
<div class="alert alert-danger">
This field is required
</div>
{{/if}}
</div>

<button type="submit" class="btn btn-primary" disabled={{formInvalid}}>Login</button>
</form>
1 change: 1 addition & 0 deletions openchat/app/templates/login.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{login-form}}

0 comments on commit 9a9a766

Please sign in to comment.