Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
Use field label when rendering field validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert committed Dec 15, 2015
1 parent e25cdae commit bd0f6cd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/helpers/get-required-registration-fields.js
Expand Up @@ -25,7 +25,7 @@ module.exports = function (config, callback) {

async.forEachOf(config.web.register.fields || {}, function (field, fieldName, cb) {
if (field && field.enabled && field.required) {
fields.push(field.name);
fields.push(field);
}

cb();
Expand Down
4 changes: 2 additions & 2 deletions lib/helpers/validate-account.js
Expand Up @@ -26,8 +26,8 @@ module.exports = function (formData, stormpathConfig, callback) {

getRequiredRegistrationFields(stormpathConfig, function (requiredFields) {
async.each(requiredFields, function (field, cb) {
if (accountFieldNames.indexOf(field) <= -1 || (accountFieldNames.indexOf(field) > -1 && !formData[field])) {
errors.push(new Error(field + ' required.'));
if (accountFieldNames.indexOf(field.name) <= -1 || (accountFieldNames.indexOf(field.name) > -1 && !formData[field.name])) {
errors.push(new Error((field.label || field.name) + ' required.'));
}

cb();
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/test-register.js
Expand Up @@ -408,7 +408,7 @@ describe('register', function () {
return done(err);
}

assert.equal(res.body.error, 'givenName required.');
assert.equal(res.body.error, 'First Name required.');

done();
});
Expand Down Expand Up @@ -606,7 +606,7 @@ describe('register', function () {

var $ = cheerio.load(res.text);
assert($('.alert.alert-danger p').length);
assert.notEqual($('.alert.alert-danger p').text().indexOf('givenName'), -1);
assert.notEqual($('.alert.alert-danger p').text().indexOf('First Name'), -1);

done();
});
Expand Down

0 comments on commit bd0f6cd

Please sign in to comment.