fix: matrix question validation (#3030)

Co-authored-by: Matti Nannt <mail@matthiasnannt.com>
This commit is contained in:
Dhruwang Jariwala
2024-08-23 15:35:28 +05:30
committed by GitHub
parent 0acc49c57d
commit ede306b88e
2 changed files with 10 additions and 10 deletions

View File

@@ -167,9 +167,11 @@ test.describe("Survey Create & Submit Response", async () => {
await expect(page.getByRole("cell", { name: surveys.createAndSubmit.matrix.columns[1] })).toBeVisible();
await expect(page.getByRole("cell", { name: surveys.createAndSubmit.matrix.columns[2] })).toBeVisible();
await expect(page.getByRole("cell", { name: surveys.createAndSubmit.matrix.columns[3] })).toBeVisible();
await expect(page.locator("#questionCard-9").getByRole("button", { name: "Next" })).not.toBeVisible();
await expect(page.locator("#questionCard-9").getByRole("button", { name: "Next" })).toBeVisible();
await expect(page.locator("#questionCard-9").getByRole("button", { name: "Back" })).toBeVisible();
await page.getByRole("row", { name: "Rose 🌹" }).getByRole("cell").nth(1).click();
await page.getByRole("row", { name: "Sunflower 🌻" }).getByRole("cell").nth(1).click();
await page.getByRole("row", { name: "Hibiscus 🌺" }).getByRole("cell").nth(1).click();
await page.locator("#questionCard-9").getByRole("button", { name: "Next" }).click();
// Address Question

View File

@@ -40,7 +40,6 @@ export const MatrixQuestion = ({
}: MatrixQuestionProps) => {
const [startTime, setStartTime] = useState(performance.now());
const isMediaAvailable = question.imageUrl || question.videoUrl;
const isSubmitButtonVisible = question.required ? Object.entries(value).length !== 0 : true;
useTtc(question.id, ttc, setTtc, startTime, setStartTime, question.id === currentQuestionId);
const handleSelect = useCallback(
@@ -152,6 +151,7 @@ export const MatrixQuestion = ({
dir="auto"
type="radio"
tabIndex={-1}
required={true}
id={`${row}-${column}`}
name={getLocalizedValue(row, languageCode)}
value={getLocalizedValue(column, languageCode)}
@@ -182,14 +182,12 @@ export const MatrixQuestion = ({
/>
)}
<div></div>
{isSubmitButtonVisible && (
<SubmitButton
buttonLabel={getLocalizedValue(question.buttonLabel, languageCode)}
isLastQuestion={isLastQuestion}
onClick={() => {}}
tabIndex={0}
/>
)}
<SubmitButton
buttonLabel={getLocalizedValue(question.buttonLabel, languageCode)}
isLastQuestion={isLastQuestion}
onClick={() => {}}
tabIndex={0}
/>
</div>
</form>
);