Skip to content

Commit

Permalink
work for the #8209
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-kurmanov committed Jun 3, 2024
1 parent fde4229 commit 0701682
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class ImagePickerItemComponent extends BaseAngular<ImageItemValue> implem
return this.model;
}
onChange(event: any) {
if (this.question.isReadOnlyAttr) return;
if (this.question.multiSelect) {
if (event.target.checked) {
this.question.value = this.question.value.concat(event.target.value);
Expand Down
15 changes: 13 additions & 2 deletions packages/survey-vue3-ui/src/ImagepickerItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:name="question.questionName"
:value="item.value"
:id="question.getItemId(item)"
v-model="question.value"
v-model="value"
:disabled="!question.getItemEnabled(item)"
:readonly="question.isReadOnlyAttr"
v-bind:aria-required="question.ariaRequired"
Expand All @@ -22,7 +22,7 @@
:name="question.questionName"
:value="item.value"
:id="question.getItemId(item)"
v-model="question.value"
v-model="value"
:disabled="!question.getItemEnabled(item)"
:readonly="question.isReadOnlyAttr"
v-bind:aria-required="question.ariaRequired"
Expand Down Expand Up @@ -116,6 +116,7 @@
<script lang="ts" setup>
import type { ImageItemValue, QuestionImagePickerModel } from "survey-core";
import { useBase, useLocString } from "./base";
import { computed } from "vue";
defineOptions({ inheritAttrs: false });
const props = defineProps<{
question: QuestionImagePickerModel;
Expand All @@ -124,6 +125,16 @@ const props = defineProps<{
const getItemClass = (item: any) => {
return props.question.getItemClass(item);
};
const value = computed({
get() {
return props.question.value;
},
set(value) {
const question = props.question;
if (question.isReadOnlyAttr) return;
question.value = value;
},
});
useBase(() => props.item);
const imageLink = useLocString(() => props.item.locImageLink);
</script>
2 changes: 1 addition & 1 deletion src/question_rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ export class QuestionRatingModel extends Question {
return !isNaN(val) ? parseFloat(val) : val;
}
public setValueFromClick(value: any) {
if (this.isReadOnlyAttr) return;
if (this.value === parseFloat(value)) {
this.clearValue(true);
} else {
Expand Down Expand Up @@ -831,7 +832,6 @@ export class QuestionRatingModel extends Question {
return false;
}
public get renderedValue(): any {
if (this.isReadOnlyAttr) return;
return this.value;
}
public set renderedValue(val: any) {
Expand Down
43 changes: 42 additions & 1 deletion testCafe/questions/imagepicker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ClientFunction, fixture, Selector, test } from "testcafe";
import { frameworks, url, initSurvey, getSurveyResult, getQuestionValue, getQuestionJson, checkSurveyWithEmptyQuestion } from "../helper";
import { frameworks, url, initSurvey, getSurveyResult, getQuestionValue, getQuestionJson, checkSurveyWithEmptyQuestion, urlV2, applyTheme } from "../helper";
// eslint-disable-next-line no-undef
const assert = require("assert");
const title = "imagepicker";
Expand Down Expand Up @@ -103,4 +103,45 @@ frameworks.forEach((framework) => {
json = JSON.parse(await getQuestionJson());
assert.equal(json.title, newTitle);
});
});

frameworks.forEach((framework) => {
fixture`${framework} ${title}`.page`${urlV2}${framework}`.beforeEach(
async (ctx) => {
const json = {
questions: [
{
"type": "imagepicker",
"name": "imagepicker",
"titleLocation": "hidden",
"choices": [
{
"value": "lion",
"imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/lion.jpg",
"text": "Lion"
},
{
"value": "giraffe",
"imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/giraffe.jpg",
"text": "Giraffe"
}
],
"readOnly": true,
"defaultValue": "lion"
}
]
};
await applyTheme("defaultV2");
await initSurvey(framework, json);
}
);

test("readonly:keyboard disabled", async (t) => {
await t.pressKey("tab").pressKey("right");
const getValue = ClientFunction(()=>{
return window["survey"].getAllQuestions()[0].value;
});
const value = await getValue();
await t.expect(value).eql("lion", "value doesn't change");
});
});
9 changes: 9 additions & 0 deletions testCafe/questions/radiogroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,4 +587,13 @@ frameworks.forEach((framework) => {
await t.expect(input.checked).eql(false);
await t.expect(Selector("input[value=BMW]").checked).eql(true);
});

test("readonly:keyboard disabled", async (t) => {
await t.pressKey("tab").pressKey("down");
const getValue = ClientFunction(()=>{
return window["survey"].getAllQuestions()[0].value;
});
const value = await getValue();
await t.expect(value).eql("BMW", "value doesn't change");
});
});
9 changes: 9 additions & 0 deletions testCafe/questions/rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,13 @@ frameworks.forEach((framework) => {
await t.expect(label1.hasClass("sd-rating__item--selected")).eql(false);
await t.expect(label3.hasClass("sd-rating__item--selected")).eql(true);
});

test("readonly:keyboard disabled", async (t) => {
await t.pressKey("tab").pressKey("right");
const getValue = ClientFunction(()=>{
return window["survey"].getAllQuestions()[0].value;
});
const value = await getValue();
await t.expect(value).eql(3, "value doesn't change");
});
});

0 comments on commit 0701682

Please sign in to comment.