Skip to content

Commit

Permalink
Added validation
Browse files Browse the repository at this point in the history
  • Loading branch information
thomheymann committed May 26, 2021
1 parent 48cf335 commit f6bddae
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,28 @@ export function validate(values: ApiKeyFormValues) {
}
}

if (values.includeMetadata) {
if (!values.metadata) {
errors.metadata = i18n.translate(
'xpack.security.management.apiKeys.createApiKey.metadataRequired',
{
defaultMessage: 'Enter metadata or disable this option.',
}
);
} else {
try {
JSON.parse(values.metadata);
} catch (e) {
errors.metadata = i18n.translate(
'xpack.security.management.apiKeys.createApiKey.invalidJsonError',
{
defaultMessage: 'Enter valid JSON.',
}
);
}
}
}

return errors;
}

Expand Down

0 comments on commit f6bddae

Please sign in to comment.