diff options
author | Avi Gaffa <avi.gaffa@amdocs.com> | 2017-09-19 10:33:06 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-09-19 10:33:06 +0000 |
commit | 25e6f5d8b68970f5d2711e91e67eda1ebef2c099 (patch) | |
tree | 3421ba445a1d3daf43dacce494200f650bf161b7 /openecomp-ui/src/nfvo-utils/Validator.js | |
parent | f87f03e2cfd224b62d1415149337ac1de6985efa (diff) | |
parent | 2c9358a92c68a28c3ea307c9036f4721c7f0ca7e (diff) |
Merge "Other option for license agreement term"
Diffstat (limited to 'openecomp-ui/src/nfvo-utils/Validator.js')
-rw-r--r-- | openecomp-ui/src/nfvo-utils/Validator.js | 21 |
1 files changed, 20 insertions, 1 deletions
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 |