From f02238ce235ddc2b009f80a7b0fe8fdb74e8f63f Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Thu, 6 Jun 2019 15:34:16 +0100 Subject: [PATCH] Fix varied validation messages and redeclaration I've hijacked the data property for the purposes of changing the message based on whether multiple values in a list are erroneous --- modules/validations/invalid_format.js | 51 +++++++++++++-------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/modules/validations/invalid_format.js b/modules/validations/invalid_format.js index c51b35cb2..2d5d35105 100644 --- a/modules/validations/invalid_format.js +++ b/modules/validations/invalid_format.js @@ -20,36 +20,44 @@ export function validationFormatting() { return !valid_scheme.test(url); } + function showReferenceEmail(selection) { + selection.selectAll('.issue-reference') + .data([0]) + .enter() + .append('div') + .attr('class', 'issue-reference') + .text(t('issues.invalid_format.email.reference')); + } + + function showReferenceWebsite(selection) { + selection.selectAll('.issue-reference') + .data([0]) + .enter() + .append('div') + .attr('class', 'issue-reference') + .text(t('issues.invalid_format.website.reference')); + } if (entity.tags.website) { // Multiple websites are possible var websites = entity.tags.website.split(';').filter(isSchemeMissing); if (websites.length) { - var multi = (websites.length > 1) ? '_multi' : ''; - issues.push(new validationIssue({ type: type, subtype: 'website', severity: 'warning', message: function() { var entity = context.hasEntity(this.entityIds[0]); - return entity ? t('issues.invalid_format.website.message' + multi, { feature: utilDisplayLabel(entity, context), site: websites.join(', ') }) : ''; + return entity ? t('issues.invalid_format.website.message' + this.data, + { feature: utilDisplayLabel(entity, context), site: websites.join(', ') }) : ''; }, reference: showReferenceWebsite, entityIds: [entity.id], - hash: websites.join() + hash: websites.join(), + data: (websites.length > 1) ? '_multi' : '' })); } - - function showReferenceWebsite(selection) { - selection.selectAll('.issue-reference') - .data([0]) - .enter() - .append('div') - .attr('class', 'issue-reference') - .text(t('issues.invalid_format.website.reference')); - } } if (entity.tags.email) { @@ -57,30 +65,21 @@ export function validationFormatting() { var emails = entity.tags.email.split(';').filter(isInvalidEmail); if (emails.length) { - var multi = (emails.length > 1) ? '_multi' : ''; - issues.push(new validationIssue({ type: type, subtype: 'email', severity: 'warning', message: function() { var entity = context.hasEntity(this.entityIds[0]); - return entity ? t('issues.invalid_format.email.message' + multi, { feature: utilDisplayLabel(entity, context), email: emails.join(', ') }) : ''; + return entity ? t('issues.invalid_format.email.message' + this.data, + { feature: utilDisplayLabel(entity, context), email: emails.join(', ') }) : ''; }, reference: showReferenceEmail, entityIds: [entity.id], - hash: emails.join() + hash: emails.join(), + data: (emails.length > 1) ? '_multi' : '' })); } - - function showReferenceEmail(selection) { - selection.selectAll('.issue-reference') - .data([0]) - .enter() - .append('div') - .attr('class', 'issue-reference') - .text(t('issues.invalid_format.email.reference')); - } } return issues;