diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/step_about_rule/field_validators.ts b/x-pack/plugins/security_solution/public/detections/components/rules/step_about_rule/field_validators.ts new file mode 100644 index 000000000000000..e4c413118a3b19d --- /dev/null +++ b/x-pack/plugins/security_solution/public/detections/components/rules/step_about_rule/field_validators.ts @@ -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 +): ReturnType> => { + const [{ value }] = args; + + if (typeof value !== 'string') { + return; + } + + return value.trim() === '' + ? { + code: 'ERR_INVALID_CHARS', + message, + } + : undefined; +}; diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/step_about_rule/schema.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/step_about_rule/schema.tsx index 3467b34d47135c5..05de05a053a88d2 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/step_about_rule/schema.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/step_about_rule/schema.tsx @@ -38,6 +38,19 @@ export const schema: FormSchema = { } ), 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, @@ -243,6 +256,19 @@ export const schema: FormSchema = { } ), 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,