@@ -11,62 +16,71 @@
name="<%= name %>"
class="left-indent <%= classes ||= '' %>"
value="<%= val ||= '' %>"
- aria-describedby="<%= tooltip ||= '' %>" />
+ aria-describedby="<%= tooltip ||= '' %>"
+ roadmap-js-id="<%= js_id %>" />
- <% if type == 'password' %>
+ <%
+ # If the field is a password then provide a 'show password' checkbox
+ if type == 'password'
+ %>
-
+
<% end %>
- <% if !tooltip.blank? %>
-
+ <%
+ # If the field has a tooltip add it and wire it up for on focus/blur
+ if !tooltip.blank?
+ %>
+
<%= tooltip %>
<% end %>
- <% # If an error handler was passed in or the input type has a generic handler %>
- <% if !error_handler.blank? || ['email', 'password'].include?(type) %>
-
+ <%
+ # If an error handler was passed in or the input type has a generic handler
+ if !error_handler.blank? || ['email', 'password'].include?(type)
+ %>
+
diff --git a/app/views/shared/_register_form.html.erb b/app/views/shared/_register_form.html.erb
index 96ffa9a..d1f2c5a 100644
--- a/app/views/shared/_register_form.html.erb
+++ b/app/views/shared/_register_form.html.erb
@@ -3,34 +3,34 @@
<% end %>
diff --git a/lib/assets/javascripts/roadmap-form.js b/lib/assets/javascripts/roadmap-form.js
index 3409d9f..143a424 100644
--- a/lib/assets/javascripts/roadmap-form.js
+++ b/lib/assets/javascripts/roadmap-form.js
@@ -2,7 +2,6 @@
});
-
// ---------------------------------------------------------------------------
function validatePassword(sPassword) {
if (sPassword.trim().length >= 8 && sPassword.trim().length <= 128){
diff --git a/lib/assets/javascripts/shared/register_form.js b/lib/assets/javascripts/shared/register_form.js
index 4e197cb..563fe81 100644
--- a/lib/assets/javascripts/shared/register_form.js
+++ b/lib/assets/javascripts/shared/register_form.js
@@ -1,71 +1,37 @@
-$(document).ready(function() {
- var email_regex = /[^@\s]+@(?:[-a-z0-9]+\.)+[a-z]{2,}$/;
- var valid_email = false;
- var valid_password = false;
- var valid_password_confirmation = false;
- var valid_accept_terms = false;
+$(document).ready(function(){
+ // If the hidden valid-form field is set to true then enable the submit button
+ $("form.user-registration #valid-form").change(function(){
+ $(this).siblings(".form-submit").attr('aria-disabled', $(this).val() != "true");
+ });
- $("#user_email.text_field.reg-input").change(function(){
- if (email_regex.test($(this).val())) {
- $(this).next().hide();
- valid_email = true;
- }
- else {
- $(this).next().show();
- valid_email = false;
- }
- set_aria_submit();
- });
- $("#user_password.text_field.reg-input").change(function() {
- if($(this).val().length >= 8) {
- $(this).next().hide();
- valid_password = true;
- }
- else {
- $(this).next().show();
- valid_password = false;
- }
- // If password_confirmation is non empty already, force to check its validity
- if($("#user_password_confirmation.text_field.reg-input").val().length > 0){
- console.log('force to check validity of confirmation');
- $("#user_password_confirmation.text_field.reg-input").change();
- }
- set_aria_submit();
- });
- $("#user_password_confirmation.text_field.reg-input").change(function() {
- if ($(this).val() === $("#user_password.text_field.reg-input").val()) {
- $(this).next().hide();
- valid_password_confirmation = true;
- }
- else {
- $(this).next().show();
- valid_password_confirmation = false;
- }
- set_aria_submit();
- });
- $("#user_accept_terms").change(function(){
- valid_accept_terms = $(this).prop('checked');
- set_aria_submit();
- });
- function set_aria_submit(){
- if(valid_email
- && valid_password
- && valid_password_confirmation
- && valid_accept_terms){
- $("#sign_up_submit").attr('aria-disabled', false);
- }
- else {
- $("#sign_up_submit").attr('aria-disabled', true);
- }
+ $("form.user-registration input[class*='required']").change(function(){
+ toggleRegisterSubmit();
+ });
+
+ $("form.user-registration #user_email, form.user-registration #user_recovery_email").blur(function(){
+ emailsMatch($(this).parent('form'));
+ });
+
+ function toggleRegisterSubmit(){
+ let disabled = ($("#user_firstname").val().trim().length <= 0 ||
+ $("#user_surname").val().trim().length <= 0 ||
+ $("#user_email").val().trim().length <= 0 ||
+ $("#user_recovery_email").val().trim().length <= 0 ||
+ $("#user_password").val().trim().length <= 0 ||
+ $("#user_email").val() === $("#user_recovery_email").val());
+ $("form.user-registration #register-button").attr('aria-disabled', disabled);
+ }
+
+ function emailsMatch(form){
+ let email = $(this).find('#user_email');
+ let recovery = $(this).find('#user_recovery_email');
+
+ if($(email).val().trim() === $(recovery).val().trim()){
+ $("span." + $(email).attr('roadmap-js-id') + "_error").html('').attr('role', '');
+ $("input[roadmap-js-id='" + $(email).attr('roadmap-js-id') + "']").removeClass('red-border');
+ }else{
+ $("span." + $(email).attr('roadmap-js-id') + "_error").attr('role', 'tooltip');
+ $("input[roadmap-js-id='" + $(email).attr('roadmap-js-id') + "']").addClass('red-border');
}
+ }
});
-
-function toggleRegisterSubmit(){
- let disabled = ($("#user_firstname").val().trim().length <= 0 ||
- $("#user_surname").val().trim().length <= 0 ||
- $("#user_email").val().trim().length <= 0 ||
- $("#user_recovery_email").val().trim().length <= 0 ||
- $("#user_password").val().trim().length <= 0 ||
- $("#user_email").val() === $("#user_recovery_email").val());
- $("#register-button").attr('aria-disabled', disabled);
-}
\ No newline at end of file
diff --git a/lib/assets/stylesheets/roadmap-form.scss b/lib/assets/stylesheets/roadmap-form.scss
index 7264ddc..9dc7e01 100644
--- a/lib/assets/stylesheets/roadmap-form.scss
+++ b/lib/assets/stylesheets/roadmap-form.scss
@@ -200,7 +200,7 @@
.error-tooltip {
display: none;
- width: 397px;
+ width: 270px;
}
.error-tooltip[role='tooltip'] {
@@ -314,6 +314,7 @@
}
#new_user fieldset {
input[type="password"],
+ #user_password,
input[type="email"] {
width: 395px;
}