Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue3: fix selected item's loc strings conflict in dropdown #9120

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/survey-vue3-ui/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,29 +148,29 @@ export function useQuestion<T extends Question>(
props.question.beforeDestroyQuestionElement(root.value);
});
}
function noop() {}
export function useLocString(
getLocString: () => LocalizableString
): Ref<string> {
const renderedHtml = ref();
const onStringChangedCallbck = (locString: LocalizableString) => {
renderedHtml.value = locString.renderedHtml;
};
const setupOnChangedCallback = (locString: LocalizableString) => {
renderedHtml.value = locString.renderedHtml;
locString.onChanged = () => {
renderedHtml.value = locString.renderedHtml;
};
locString.onStringChanged.add(onStringChangedCallbck);
};
const stopWatch = watch(
getLocString,
(newValue, oldValue) => {
if (oldValue) oldValue.onChanged = noop;
if (oldValue) oldValue.onStringChanged.remove(onStringChangedCallbck);
setupOnChangedCallback(newValue);
},
{ immediate: true }
);
onBeforeUnmount(() => {
const locString = getLocString();
if (locString) {
locString.onChanged = noop;
locString.onStringChanged.remove(onStringChangedCallbck);
}
stopWatch();
});
Expand Down
51 changes: 51 additions & 0 deletions testCafe/questions/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -2267,4 +2267,55 @@ frameworks.forEach((framework) => {
let surveyResult = await getSurveyResult();
await t.expect(surveyResult).eql({ q1: { row1: { col1: "other", "col1-Comment": "ABC" } } });
});
});
frameworks.forEach((framework) => {
fixture`${framework} ${title}`.page`${url}${framework}`;
test("Check item title changes when locale is changed", async (t) => {
await initSurvey(framework, {
locale: "de",
elements: [
{
defaultValue: "one",
choices: [
{
text: {
default: "english",
de: "notenglish",
},
value: "one",
},
],
name: "q1",
title: {
default: "english",
de: "notenglish",
},
type: "dropdown",
},
],
});
const changeLocale = ClientFunction((locale) => {
window.survey.locale = locale;
});
await t
.expect(Selector(".sv_q_dropdown__value span").withExactText("notenglish").exists).ok()
.click("input")
.expect(Selector("li div").withAttribute("title", "notenglish").exists).ok()
.expect(Selector("li div span").withExactText("notenglish").exists).ok()
.click("body", { offsetX: 0 });
await changeLocale("en");
await t
.expect(Selector(".sv_q_dropdown__value span").withExactText("english").exists).ok()
.click("input")
.expect(Selector("li div").withAttribute("title", "english").exists).ok()
.expect(Selector("li div span").withExactText("english").exists).ok()
.click("body", { offsetX: 0 });
await changeLocale("de");
await t
.expect(Selector(".sv_q_dropdown__value span").withExactText("notenglish").exists).ok()
.click("input")
.expect(Selector("li div").withAttribute("title", "notenglish").exists).ok()
.expect(Selector("li div span").withExactText("notenglish").exists).ok()
.click("body", { offsetX: 0 });
});
});