Browse Source

fix: robust option_id mapping in createQuestionField

master
mortezaei 4 days ago
parent
commit
923a7c6219
  1. 12
      src/components/Componentes/question-answer-storage.tsx

12
src/components/Componentes/question-answer-storage.tsx

@ -136,7 +136,17 @@ function createQuestionField(
if (Array.isArray(value)) { if (Array.isArray(value)) {
option_id = value; option_id = value;
} else if (typeof value === "string" && value) { } else if (typeof value === "string" && value) {
const selectedOpt = question.options.find((opt) => opt.id === value || opt.value === value);
const strVal = value.trim().toLowerCase();
const selectedOpt = question.options.find(
(opt) =>
opt.id === value ||
opt.value === value ||
opt.label === value ||
opt.id.toLowerCase() === strVal ||
(typeof opt.value === "string" && opt.value.toLowerCase() === strVal) ||
(typeof opt.label === "string" && opt.label.toLowerCase() === strVal) ||
opt.id.toLowerCase().endsWith(`.${strVal}`)
);
option_id = selectedOpt ? selectedOpt.id : value; option_id = selectedOpt ? selectedOpt.id : value;
} }
} }

Loading…
Cancel
Save