-
Notifications
You must be signed in to change notification settings - Fork 11
issue 19 #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
issue 19 #169
Changes from 4 commits
b5ca790
1861b7e
e7a129d
24eee4c
26a337b
4036651
bea7a5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,14 @@ | |
<%= f.email_field :email %></p> | ||
<p><b>Password</b><br/> | ||
<%= f.password_field :password %></p> | ||
<div id="pswd_info" > | ||
<h4>Password must meet the following requirements:</h4> | ||
<u1> | ||
<li id ="letter" class="invalid">At least <strong>one letter</strong></li> | ||
<li id="number" class ="invalid">At least <strong>one number</strong></li> | ||
<li id="length" class="invalid">At least <strong>8 characters</strong></li> | ||
</u1> | ||
</div> | ||
<p><b>Password Confirmation</b><br/> | ||
<%= f.password_field :password_confirmation %></p> | ||
|
||
|
@@ -41,15 +49,70 @@ | |
<%# JS to enable/disable the submit button dependent on if the agree checkbox is checked %> | ||
<% content_for :javascript do %> | ||
<%= javascript_tag do %> | ||
var len = false; | ||
var letter = false; | ||
var number = false; | ||
$('#agreement_checkbox').live('click', function() { | ||
if ($('#agreement_checkbox').is(':checked')) { | ||
$('#register_submit').removeAttr('disabled'); | ||
$('#register_submit').removeClass('ui-state-disabled'); | ||
} | ||
if ($('#agreement_checkbox').is(':checked') & (len == true)& (letter == true) & (number == true)){ | ||
$('#register_submit').removeAttr('disabled'); | ||
$('#register_submit').removeClass('ui-state-disabled'); | ||
|
||
} | ||
else { | ||
$('#register_submit').attr('disabled', 'disabled'); | ||
$('#register_submit').addClass('ui-state-disabled'); | ||
} | ||
}); | ||
|
||
$('input[type=password]').keyup(function(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And you could to the same here, just call $('input[type=password]').keyup(checkPassword); Seems like the last 2 else's are the same and could be combined, like above. |
||
if ($('#agreement_checkbox').is(':checked') & (len == true)& (letter == true) & (number == true)){ | ||
$('#register_submit').removeAttr('disabled'); | ||
$('#register_submit').removeClass('ui-state-disabled'); | ||
|
||
} | ||
else if ($(len == false) | (letter == false) | (number == false)){ | ||
$('#register_submit').attr('disabled', 'disabled'); | ||
$('#register_submit').addClass('ui-state-disabled'); | ||
} | ||
else { | ||
$('#register_submit').attr('disabled', 'disabled'); | ||
$('#register_submit').addClass('ui-state-disabled'); | ||
} | ||
}); | ||
|
||
$('input[type=password]').keyup(function(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to make this affect only the main password field, and add a separate check for the confirmation matching. Of course, the other check should be triggered when typing to both the main field and the confirmation field. |
||
//set password variable | ||
var pswd = $(this).val(); | ||
|
||
//validate the length | ||
if (pswd.length < 8) { | ||
$('#length').removeClass('valid').addClass('invalid'); | ||
len = false; | ||
} else { | ||
$('#length').removeClass('invalid').addClass('valid'); | ||
len = true; | ||
} | ||
//validate letter | ||
if (pswd.match(/[A-z]/)){ | ||
$('#letter').removeClass('invalid').addClass('valid'); | ||
letter = true; | ||
} else { | ||
$('#letter').removeClass('valid').addClass('invalid'); | ||
letter = false; | ||
} | ||
//validate number | ||
if (pswd.match(/\d/)){ | ||
$('#number').removeClass('invalid').addClass('valid'); | ||
number = true; | ||
} else { | ||
$('#number').removeClass('valid').addClass('invalid'); | ||
number = false; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice. Can you add one more check that is valid if the password and the confirmation match? |
||
}).focus(function(){ | ||
$('#pswd_info').show(); | ||
}).blur(function(){ | ||
$('#pswd_info').hide(); | ||
}); | ||
<% end %> | ||
<% end %> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you abstract this if statement and the contents into some JS function, to avoid repeating the code. Just call it checkPassword(event) or something like that (don't worry about the event variable), then you can probably call it like: $('#agreement_checkbox').on('click', checkPassword)