Improved form validation.
This commit is contained in:
parent
57d0b22e09
commit
87bd535ad5
4 changed files with 19 additions and 18 deletions
|
@ -623,10 +623,10 @@ class App.ControllerForm extends App.Controller
|
||||||
|
|
||||||
|
|
||||||
@enable: (form) ->
|
@enable: (form) ->
|
||||||
App.Log.log 'ControllerForm', 'notice', 'enable...', $(form).parent()
|
App.Log.log 'ControllerForm', 'notice', 'enable...', $(form.target).parent()
|
||||||
$(form).parent().find('button').attr('disabled', false)
|
$(form.target).parent().find('button').attr('disabled', false)
|
||||||
$(form).parent().find('[type="submit"]').attr('disabled', false)
|
$(form.target).parent().find('[type="submit"]').attr('disabled', false)
|
||||||
$(form).parent().find('[type="reset"]').attr('disabled', false)
|
$(form.target).parent().find('[type="reset"]').attr('disabled', false)
|
||||||
|
|
||||||
@validate: (data) ->
|
@validate: (data) ->
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ class Index extends App.Controller
|
||||||
|
|
||||||
login: (e) ->
|
login: (e) ->
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
@formDisable(e)
|
||||||
params = @formParam(e.target)
|
params = @formParam(e.target)
|
||||||
|
|
||||||
# remember username
|
# remember username
|
||||||
|
|
|
@ -27,18 +27,18 @@ class Index extends App.Controller
|
||||||
@html App.view('signup')()
|
@html App.view('signup')()
|
||||||
|
|
||||||
new App.ControllerForm(
|
new App.ControllerForm(
|
||||||
el: @el.find('#form-signup'),
|
el: @el.find('#form-signup')
|
||||||
model: App.User,
|
model: App.User
|
||||||
required: 'signup',
|
required: 'signup'
|
||||||
autofocus: true,
|
autofocus: true
|
||||||
)
|
)
|
||||||
|
|
||||||
cancel: ->
|
cancel: ->
|
||||||
@navigate 'login'
|
@navigate 'login'
|
||||||
|
|
||||||
submit: (e) ->
|
submit: (e) ->
|
||||||
@log 'submit'
|
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
@formDisable(e)
|
||||||
@params = @formParam(e.target)
|
@params = @formParam(e.target)
|
||||||
|
|
||||||
# if no login is given, use emails as fallback
|
# if no login is given, use emails as fallback
|
||||||
|
@ -54,18 +54,18 @@ class Index extends App.Controller
|
||||||
if errors
|
if errors
|
||||||
@log 'error new', errors
|
@log 'error new', errors
|
||||||
@formValidate( form: e.target, errors: errors )
|
@formValidate( form: e.target, errors: errors )
|
||||||
|
@formEnable(e)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
# save user
|
# save user
|
||||||
user.save(
|
user.save(
|
||||||
success: (r) =>
|
success: (r) =>
|
||||||
App.Auth.login(
|
App.Auth.login(
|
||||||
data: {
|
data:
|
||||||
username: @params.login,
|
username: @params.login
|
||||||
password: @params.password,
|
password: @params.password
|
||||||
},
|
|
||||||
success: @success
|
success: @success
|
||||||
error: @error,
|
error: @error
|
||||||
)
|
)
|
||||||
# error: =>
|
# error: =>
|
||||||
# @modalHide()
|
# @modalHide()
|
||||||
|
@ -90,13 +90,13 @@ class Index extends App.Controller
|
||||||
# add notify
|
# add notify
|
||||||
App.Event.trigger 'notify:removeall'
|
App.Event.trigger 'notify:removeall'
|
||||||
App.Event.trigger 'notify', {
|
App.Event.trigger 'notify', {
|
||||||
type: 'warning',
|
type: 'warning'
|
||||||
msg: 'Wrong Username and Password combination.',
|
msg: 'Wrong Username and Password combination.'
|
||||||
}
|
}
|
||||||
|
|
||||||
# rerender login page
|
# rerender login page
|
||||||
@render(
|
@render(
|
||||||
msg: 'Wrong Username and Password combination.',
|
msg: 'Wrong Username and Password combination.'
|
||||||
username: @username
|
username: @username
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="span12">
|
<div class="span12">
|
||||||
<p><%- @T( 'Sign in with' ) %></p>
|
<p><%- @T( 'Sign in with' ) %></p>
|
||||||
<form id="login" class="form-search">
|
<form id="login" class="form-search" method="post">
|
||||||
<input name="username" type="text" class="input span3" placeholder="<%- @Ti( 'Username or email' ) %>" value="<%= @item.username %>" autocapitalize="off"/>
|
<input name="username" type="text" class="input span3" placeholder="<%- @Ti( 'Username or email' ) %>" value="<%= @item.username %>" autocapitalize="off"/>
|
||||||
<input name="password" type="password" class="input span3" placeholder="<%- @Ti( 'Password' ) %>"/>
|
<input name="password" type="password" class="input span3" placeholder="<%- @Ti( 'Password' ) %>"/>
|
||||||
<button class="btn btn-primary" type="submit"><%- @T( 'Sign in' ) %></button>
|
<button class="btn btn-primary" type="submit"><%- @T( 'Sign in' ) %></button>
|
||||||
|
|
Loading…
Reference in a new issue