mirror of
https://github.com/formbricks/formbricks.git
synced 2026-03-18 00:41:13 -05:00
fix: removed validation from button labels (#7138)
This commit is contained in:
committed by
GitHub
parent
8d47ab9709
commit
22ea7302bb
@@ -36,7 +36,6 @@ import { PictureSelectionForm } from "@/modules/survey/editor/components/picture
|
||||
import { RankingElementForm } from "@/modules/survey/editor/components/ranking-element-form";
|
||||
import { RatingElementForm } from "@/modules/survey/editor/components/rating-element-form";
|
||||
import { formatTextWithSlashes } from "@/modules/survey/editor/lib/utils";
|
||||
import { isLabelValidForAllLanguages } from "@/modules/survey/editor/lib/validation";
|
||||
import { getElementIconMap, getTSurveyElementTypeEnumName } from "@/modules/survey/lib/elements";
|
||||
import { Alert, AlertButton, AlertTitle } from "@/modules/ui/components/alert";
|
||||
|
||||
@@ -128,25 +127,7 @@ export const BlockCard = ({
|
||||
const isBlockOpen = block.elements.some((element) => element.id === activeElementId);
|
||||
|
||||
const hasInvalidElement = block.elements.some((element) => invalidElements?.includes(element.id));
|
||||
|
||||
// Check if button labels have incomplete translations for any enabled language
|
||||
// A button label is invalid if it exists but doesn't have valid text for all enabled languages
|
||||
const surveyLanguages = localSurvey.languages ?? [];
|
||||
const hasInvalidButtonLabel =
|
||||
block.buttonLabel !== undefined &&
|
||||
block.buttonLabel["default"]?.trim() !== "" &&
|
||||
!isLabelValidForAllLanguages(block.buttonLabel, surveyLanguages);
|
||||
|
||||
// Check if back button label is invalid
|
||||
// Back button label should exist for all blocks except the first one
|
||||
const hasInvalidBackButtonLabel =
|
||||
blockIdx > 0 &&
|
||||
block.backButtonLabel !== undefined &&
|
||||
block.backButtonLabel["default"]?.trim() !== "" &&
|
||||
!isLabelValidForAllLanguages(block.backButtonLabel, surveyLanguages);
|
||||
|
||||
// Block should be highlighted if it has invalid elements OR invalid button labels
|
||||
const isBlockInvalid = hasInvalidElement || hasInvalidButtonLabel || hasInvalidBackButtonLabel;
|
||||
const isBlockInvalid = hasInvalidElement;
|
||||
|
||||
const [isBlockCollapsed, setIsBlockCollapsed] = useState(false);
|
||||
const [openAdvanced, setOpenAdvanced] = useState(blockLogic.length > 0);
|
||||
|
||||
@@ -45,7 +45,6 @@ import {
|
||||
FORBIDDEN_IDS,
|
||||
findLanguageCodesForDuplicateLabels,
|
||||
findQuestionsWithCyclicLogic,
|
||||
getTextContent,
|
||||
isConditionGroup,
|
||||
validateCardFieldsForAllLanguages,
|
||||
validateQuestionLabels,
|
||||
@@ -1334,68 +1333,7 @@ export const ZSurvey = z
|
||||
|
||||
// 4. Detailed validation for each block and its elements
|
||||
blocks.forEach((block, blockIndex) => {
|
||||
// Validate block button labels
|
||||
const defaultLanguageCode = "default";
|
||||
|
||||
if (
|
||||
block.buttonLabel?.[defaultLanguageCode] &&
|
||||
block.buttonLabel[defaultLanguageCode].trim() !== ""
|
||||
) {
|
||||
// Validate button label for all enabled languages
|
||||
const enabledLanguages = languages.filter((lang) => lang.enabled);
|
||||
const languageCodes = enabledLanguages.map((lang) =>
|
||||
lang.default ? "default" : lang.language.code
|
||||
);
|
||||
|
||||
for (const languageCode of languageCodes.length === 0 ? ["default"] : languageCodes) {
|
||||
const labelValue = block.buttonLabel[languageCode];
|
||||
if (!labelValue || getTextContent(labelValue).length === 0) {
|
||||
const invalidLanguageCode =
|
||||
languageCode === "default"
|
||||
? (languages.find((lang) => lang.default)?.language.code ?? "default")
|
||||
: languageCode;
|
||||
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `The buttonLabel in block ${String(blockIndex + 1)} is missing for the following languages: ${invalidLanguageCode}`,
|
||||
path: ["blocks", blockIndex, "buttonLabel"],
|
||||
params: { invalidLanguageCodes: [invalidLanguageCode] },
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//only validate back button label for blocks other than the first one and if back button is not hidden
|
||||
if (
|
||||
!isBackButtonHidden &&
|
||||
blockIndex > 0 &&
|
||||
block.backButtonLabel?.[defaultLanguageCode] &&
|
||||
block.backButtonLabel[defaultLanguageCode].trim() !== ""
|
||||
) {
|
||||
// Validate back button label for all enabled languages
|
||||
const enabledLanguages = languages.filter((lang) => lang.enabled);
|
||||
const languageCodes = enabledLanguages.map((lang) =>
|
||||
lang.default ? "default" : lang.language.code
|
||||
);
|
||||
|
||||
for (const languageCode of languageCodes.length === 0 ? ["default"] : languageCodes) {
|
||||
const labelValue = block.backButtonLabel[languageCode];
|
||||
if (!labelValue || getTextContent(labelValue).length === 0) {
|
||||
const invalidLanguageCode =
|
||||
languageCode === "default"
|
||||
? (languages.find((lang) => lang.default)?.language.code ?? "default")
|
||||
: languageCode;
|
||||
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `The backButtonLabel in block ${String(blockIndex + 1)} is missing for the following languages: ${invalidLanguageCode}`,
|
||||
path: ["blocks", blockIndex, "backButtonLabel"],
|
||||
params: { invalidLanguageCodes: [invalidLanguageCode] },
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Validate each element in the block
|
||||
block.elements.forEach((element, elementIndex) => {
|
||||
// Validate headline (required for all elements)
|
||||
|
||||
Reference in New Issue
Block a user