Skip to content

Commit

Permalink
Fixed event validation of details with boolean default field
Browse files Browse the repository at this point in the history
  • Loading branch information
Alf-Melmac committed Dec 3, 2022
1 parent 5425b83 commit da7bf44
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/features/event/action/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export const eventActionValidate = (values: EventAction, active?: number) => {
if (!activePresent || active === 1) {
values.details.forEach((field, i) => {
errors[`details.${i}.title`] = requiredFieldWithMaxLength(field.title, EMBEDDABLE_TITLE);
errors[`details.${i}.text`] = requiredFieldWithMaxLength(field.text, EMBEDDABLE_VALUE);
// noinspection SuspiciousTypeOfGuard Text may be boolean if using default field
if (typeof field.text === 'string') {
errors[`details.${i}.text`] = requiredFieldWithMaxLength(field.text, EMBEDDABLE_VALUE);
}
});
validateEmbedSize(values, errors);
}
Expand Down Expand Up @@ -62,16 +65,14 @@ function ifPresentAddLength(field: string, supplementaryText = 0): number {

function detailsFieldTextLength(field: EventAction['details'][number]): number {
let fieldLength = length(field.title);
switch (field.text) {
case "true":
fieldLength += 2; //"Ja"
break;
case "false":
fieldLength += 4; //"Nein"
break;
default:
fieldLength += length(field.text); //Currently this doesn't respect auto generated links
break;
// @ts-ignore Text may be boolean if using default field
if (field.text === "true" || field.text === true) {
fieldLength += 2; //"Ja"
// @ts-ignore Text may be boolean if using default field
} else if (field.text === "false" || field.text === false) {
fieldLength += 4; //"Nein"
} else {
fieldLength += length(field.text); //Currently this doesn't respect auto generated links
}
return fieldLength;
}
Expand Down

0 comments on commit da7bf44

Please sign in to comment.