diff --git a/common/static/js/spec_helpers/edx.utils.validate.js b/common/static/js/spec_helpers/edx.utils.validate.js index db1fe96063..cf41b58568 100644 --- a/common/static/js/spec_helpers/edx.utils.validate.js +++ b/common/static/js/spec_helpers/edx.utils.validate.js @@ -10,29 +10,40 @@ var edx = edx || {}; validate: { msg: { - email: '

A properly formatted e-mail is required

', - min: '

<%= field %> must be a minimum of <%= length %> characters long', - max: '

<%= field %> must be a maximum of <%= length %> characters long', - password: '

A valid password is required

', - required: '

<%= field %> field is required

', - terms: '

To enroll you must agree to the Terms of Service and Honor Code

' + email: '
  • A properly formatted e-mail is required
  • ', + min: '
  • <%= field %> must be a minimum of <%= count %> characters long
  • ', + max: '
  • <%= field %> must be a maximum of <%= count %> characters long
  • ', + password: '
  • A valid password is required
  • ', + required: '
  • <%= field %> field is required
  • ', + terms: '
  • To enroll you must agree to the Terms of Service and Honor Code
  • ' }, field: function( el ) { var $el = $(el), - required = _fn.validate.required( $el ), - // length = _fn.validate.charLength( $el ), - min = _fn.validate.str.minlength( $el ), - max = _fn.validate.str.maxlength( $el ), - email = _fn.validate.email.valid( $el ), - response = { - isValid: required && min && max && email - }; + required = true, + min = true, + max = true, + email = true, + response = {}, + isBlank = _fn.validate.isBlank( $el ); + + if ( _fn.validate.isRequired( $el ) ) { + if ( isBlank ) { + required = false; + } else { + min = _fn.validate.str.minlength( $el ); + max = _fn.validate.str.maxlength( $el ); + email = _fn.validate.email.valid( $el ); + } + } else if ( !isBlank ) { + email = _fn.validate.email.valid( $el ); + } + + response.isValid = required && min && max && email; if ( !response.isValid ) { response.message = _fn.validate.getMessage( $el, { required: required, - // length: length, min: min, max: max, email: email @@ -42,28 +53,6 @@ var edx = edx || {}; return response; }, - charLength: function( $el ) { - var type = $el.attr("type"); - if (type !== "text" && type !== "textarea" && type !== "password") { - return true; - } - - // Cannot assume there will be both min and max - var min = $el.attr('minlength') || 0, - max = $el.attr('maxlength') || false, - chars = $el.val().length, - within = false; - - // if max && min && within the range - if ( min <= chars && ( max && chars <= max ) ) { - within = true; - } else if ( min <= chars && !max ) { - within = true; - } - - return within; - }, - str: { minlength: function( $el ) { var min = $el.attr('minlength') || 0; @@ -84,12 +73,12 @@ var edx = edx || {}; } }, - required: function( $el ) { - if ( $el.attr('type') === 'checkbox' ) { - return $el.attr('required') ? $el.prop('checked') : true; - } else { - return $el.attr('required') ? $el.val() : true; - } + isRequired: function( $el ) { + return $el.attr('required'); + }, + + isBlank: function( $el ) { + return ( $el.attr('type') === 'checkbox' ) ? $el.prop('checked') : !$el.val(); }, email: { @@ -104,7 +93,7 @@ var edx = edx || {}; ), valid: function( $el ) { - return $el.data('email') ? _fn.validate.email.format( $el.val() ) : true; + return $el.attr('type') === 'email' ? _fn.validate.email.format( $el.val() ) : true; }, format: function( str ) { @@ -115,7 +104,8 @@ var edx = edx || {}; getMessage: function( $el, tests ) { var txt = [], tpl, - name; + name, + obj; _.each( tests, function( value, key ) { if ( !value ) { @@ -123,9 +113,17 @@ var edx = edx || {}; tpl = _fn.validate.msg[key]; - txt.push( _.template( tpl, { + obj = { field: _fn.validate.str.capitalizeFirstLetter( name ) - })); + }; + + if ( key === 'min' ) { + obj.count = $el.attr('minlength'); + } else if ( key === 'max' ) { + obj.count = $el.attr('maxlength'); + } + + txt.push( _.template( tpl, obj ) ); } }); diff --git a/lms/static/js/student_account/views/PasswordResetView.js b/lms/static/js/student_account/views/PasswordResetView.js index e6cd326b59..48b4480998 100644 --- a/lms/static/js/student_account/views/PasswordResetView.js +++ b/lms/static/js/student_account/views/PasswordResetView.js @@ -15,6 +15,8 @@ var edx = edx || {}; 'click .js-reset': 'submitForm' }, + formType: 'password-reset', + requiredStr: '', postRender: function() { diff --git a/lms/static/js/student_account/views/RegisterView.js b/lms/static/js/student_account/views/RegisterView.js index 6be3e3a562..697c19cf7c 100644 --- a/lms/static/js/student_account/views/RegisterView.js +++ b/lms/static/js/student_account/views/RegisterView.js @@ -16,6 +16,8 @@ var edx = edx || {}; 'click .login-provider': 'thirdPartyAuth' }, + formType: 'register', + initialize: function( data ) { this.tpl = $(this.tpl).html(); this.fieldTpl = $(this.fieldTpl).html(); diff --git a/lms/static/sass/multicourse/_account.scss b/lms/static/sass/multicourse/_account.scss index 0c4243dce7..77ba0b0301 100644 --- a/lms/static/sass/multicourse/_account.scss +++ b/lms/static/sass/multicourse/_account.scss @@ -585,7 +585,7 @@ list-style: none; li { - margin: 0 0 ($baseline/4) 0; + margin: 0; /*0 0 ($baseline/4) 0;*/ } } } @@ -598,10 +598,6 @@ .message-title { color: shade($red, 10%) !important; } - - .message-copy { - - } } // misc diff --git a/lms/templates/student_account/login.underscore b/lms/templates/student_account/login.underscore index d92d26aa90..604d847fe8 100644 --- a/lms/templates/student_account/login.underscore +++ b/lms/templates/student_account/login.underscore @@ -1,9 +1,7 @@