Skip to content

Commit

Permalink
Add empty string validation for Tags and Authors
Browse files Browse the repository at this point in the history
  • Loading branch information
machadoum committed Jun 9, 2021
1 parent 520d1e8 commit f5e3d13
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { ValidationFunc, ERROR_CODE } from '../../../../shared_imports';

export const emptyArrayItem = (message: string) => (
...args: Parameters<ValidationFunc>
): ReturnType<ValidationFunc<FormData, ERROR_CODE>> => {
const [{ value }] = args;

if (typeof value !== 'string') {
return;
}

return value.trim() === ''
? {
code: 'ERR_INVALID_CHARS',
message,
}
: undefined;
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ export const schema: FormSchema<AboutStepRule> = {
}
),
labelAppend: OptionalFieldLabel,
validations: [
{
validator: emptyArrayItem(
i18n.translate(
'xpack.securitySolution.detectionEngine.createRule.stepAboutRule.tagFieldEmptyError',
{
defaultMessage: 'An author must not be empty',
}
)
),
type: 'arrayItem',
},
],
},
name: {
type: FIELD_TYPES.TEXT,
Expand Down Expand Up @@ -243,6 +256,19 @@ export const schema: FormSchema<AboutStepRule> = {
}
),
labelAppend: OptionalFieldLabel,
validations: [
{
validator: emptyArrayItem(
i18n.translate(
'xpack.securitySolution.detectionEngine.createRule.stepAboutRule.tagFieldEmptyError',
{
defaultMessage: 'A tag must not be empty',
}
)
),
type: 'arrayItem',
},
],
},
note: {
type: FIELD_TYPES.TEXTAREA,
Expand Down

0 comments on commit f5e3d13

Please sign in to comment.