[Cases] Fix form case tags displaying error when all tags are removed (#123172)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Esteban Beltran 2022-01-18 11:33:40 +01:00 committed by GitHub
parent cb3e0ec67a
commit d7aacd723c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,6 +18,8 @@ import * as i18n from './translations';
import { OptionalFieldLabel } from './optional_field_label';
const { emptyField, maxLengthField } = fieldValidators;
const isEmptyString = (value: string) => value.trim() === '';
export const schemaTags = {
type: FIELD_TYPES.COMBO_BOX,
label: i18n.TAGS,
@ -25,7 +27,16 @@ export const schemaTags = {
labelAppend: OptionalFieldLabel,
validations: [
{
validator: emptyField(i18n.TAGS_EMPTY_ERROR),
validator: ({ value }: { value: string | string[] }) => {
if (
(!Array.isArray(value) && isEmptyString(value)) ||
(Array.isArray(value) && value.length > 0 && value.find(isEmptyString))
) {
return {
message: i18n.TAGS_EMPTY_ERROR,
};
}
},
type: VALIDATION_TYPES.ARRAY_ITEM,
isBlocking: false,
},