From 2c9358a92c68a28c3ea307c9036f4721c7f0ca7e Mon Sep 17 00:00:00 2001 From: ilanap Date: Wed, 13 Sep 2017 14:41:21 +0300 Subject: Other option for license agreement term Issue-Id: SDC-290 Change-Id: Ifeae84fd96175b656814e8b70bc67789f57ef78e Signed-off-by: ilanap --- openecomp-ui/src/nfvo-utils/Validator.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'openecomp-ui/src/nfvo-utils') diff --git a/openecomp-ui/src/nfvo-utils/Validator.js b/openecomp-ui/src/nfvo-utils/Validator.js index 1df82a2ada..3f6a00e289 100644 --- a/openecomp-ui/src/nfvo-utils/Validator.js +++ b/openecomp-ui/src/nfvo-utils/Validator.js @@ -46,7 +46,25 @@ class Validator { email: value => ValidatorJS.isEmail(value), ip: value => ValidatorJS.isIP(value), url: value => ValidatorJS.isURL(value), - alphanumericWithUnderscores: value => ValidatorJS.isAlphanumeric(value.replace(/_/g, '')) + alphanumericWithUnderscores: value => ValidatorJS.isAlphanumeric(value.replace(/_/g, '')), + requiredChoiceWithOther: (value, otherValue) => { + let chosen = value.choice; + // if we have an empty multiple select we have a problem since it's required + let validationFunc = this.globalValidationFunctions['required']; + if (value.choices) { + if (value.choices.length === 0) { + return false; + } else { + // continuing validation with the first chosen value in case we have the 'Other' field + chosen = value.choices[0]; + } + } + if (chosen !== otherValue) { + return validationFunc(chosen, true); + } else { // when 'Other' was chosen, validate other value + return validationFunc(value.other, true); + } + } }; } @@ -54,6 +72,7 @@ class Validator { return { required: () => i18n('Field is required'), requiredChooseOption: () => i18n('Field should have one of these options'), + requiredChoiceWithOther: () => i18n('Field is required'), maxLength: (value, maxLength) => i18n('Field value has exceeded it\'s limit, {maxLength}. current length: {length}', { length: value.length, maxLength -- cgit 1.2.3-korg