mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-21 06:19:01 -06:00
feat: adds line break support in open text question textarea (#6456)
This commit is contained in:
@@ -138,7 +138,7 @@ export function OpenTextQuestion({
|
||||
tabIndex={isCurrent ? 0 : -1}
|
||||
aria-label="textarea"
|
||||
id={question.id}
|
||||
placeholder={getLocalizedValue(question.placeholder, languageCode)}
|
||||
placeholder={getLocalizedValue(question.placeholder, languageCode, true)}
|
||||
dir={dir}
|
||||
required={question.required}
|
||||
value={value}
|
||||
|
||||
@@ -5,15 +5,31 @@ const isI18nObject = (obj: any): obj is TI18nString => {
|
||||
return typeof obj === "object" && obj !== null && Object.keys(obj).includes("default");
|
||||
};
|
||||
|
||||
export const getLocalizedValue = (value: TI18nString | undefined, languageId: string): string => {
|
||||
// Matches \r\n, \n, \r, and their HTML entity variants
|
||||
const ESCAPED_NEWLINES = /\\r\\n| |\\n|\\r| | /g;
|
||||
|
||||
export const unescapeNewlines = (s: string): string => s.replace(ESCAPED_NEWLINES, "\n");
|
||||
|
||||
export const getLocalizedValue = (
|
||||
value: TI18nString | undefined,
|
||||
languageId: string,
|
||||
replaceNewLines: boolean = false
|
||||
): string => {
|
||||
if (!value) {
|
||||
return "";
|
||||
}
|
||||
|
||||
let result = "";
|
||||
|
||||
if (isI18nObject(value)) {
|
||||
if (typeof value[languageId] === "string") {
|
||||
return value[languageId];
|
||||
result = value[languageId];
|
||||
} else {
|
||||
result = value.default;
|
||||
}
|
||||
return value.default;
|
||||
|
||||
result = replaceNewLines ? unescapeNewlines(result) : result;
|
||||
}
|
||||
return "";
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user