Merge pull request #5914 from edx/renzo/final-text-review

Final text review
This commit is contained in:
Renzo Lucioni
2014-11-12 09:55:48 -05:00
6 changed files with 50 additions and 30 deletions

View File

@@ -9,9 +9,10 @@ describe('edx.utils.validate', function () {
VALID_STRING = 'xsy_is_awesome',
SHORT_STRING = 'x',
LONG_STRING = 'xsy_is_way_too_awesome',
REQUIRED_ERROR_FRAGMENT = 'required',
EMAIL_ERROR_FRAGMENT = 'formatted',
MIN_ERROR_FRAGMENT = 'least',
MAX_ERROR_FRAGMENT = 'up to',
REQUIRED_ERROR_FRAGMENT = 'empty',
CUSTOM_MESSAGE = 'custom message';
var createFixture = function( type, name, required, minlength, maxlength, value ) {
@@ -117,11 +118,11 @@ describe('edx.utils.validate', function () {
createFixture('email', 'email', false, MIN_LENGTH, MAX_LENGTH, 'localpart');
// Verify optional field behavior
expectInvalid('invalid');
expectInvalid(EMAIL_ERROR_FRAGMENT);
// Verify required field behavior
field.prop('required', false);
expectInvalid('invalid');
expectInvalid(EMAIL_ERROR_FRAGMENT);
});
it('succeeds if an email field is provided a valid address', function () {

View File

@@ -18,10 +18,10 @@ var edx = edx || {};
validate: {
msg: {
email: '<li><%- gettext("The email address you\'ve provided is invalid.") %></li>',
min: '<li><%- _.sprintf(gettext("%(field)s must have at least %(count)d characters"), context) %></li>',
max: '<li><%- _.sprintf(gettext("%(field)s can only contain up to %(count)d characters"), context) %></li>',
required: '<li><%- _.sprintf(gettext("%(field)s is required"), context) %></li>',
email: '<li><%- gettext("The email address you\'ve provided isn\'t formatted correctly.") %></li>',
min: '<li><%- _.sprintf(gettext("%(field)s must have at least %(count)d characters."), context) %></li>',
max: '<li><%- _.sprintf(gettext("%(field)s can only contain up to %(count)d characters."), context) %></li>',
required: '<li><%- _.sprintf(gettext("The %(field)s field cannot be empty."), context) %></li>',
custom: '<li><%= content %></li>'
},
@@ -73,12 +73,6 @@ var edx = edx || {};
var max = $el.attr('maxlength') || false;
return ( !!max ) ? max >= $el.val().length : true;
},
capitalizeFirstLetter: function( str ) {
str = str.replace('_', ' ');
return str.charAt(0).toUpperCase() + str.slice(1);
}
},
@@ -121,16 +115,21 @@ var edx = edx || {};
}
},
getLabel: function( id ) {
// Extract the field label, remove the asterisk (if it appears) and any extra whitespace
return $("label[for=" + id + "]").text().split("*")[0].trim();
},
getMessage: function( $el, tests ) {
var txt = [],
tpl,
name,
label,
obj,
customMsg;
_.each( tests, function( value, key ) {
if ( !value ) {
name = $el.attr('name');
label = _fn.validate.getLabel( $el.attr('id') );
customMsg = $el.data('errormsg-' + key) || false;
// If the field has a custom error msg attached, use it
@@ -147,7 +146,7 @@ var edx = edx || {};
// We pass the context object to the template so that
// we can perform variable interpolation using sprintf
context: {
field: _fn.validate.str.capitalizeFirstLetter( name )
field: label
}
};