mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-28 01:20:24 -05:00
fix: hidden field not working with prefilling on 1st question (#1602)
Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
This commit is contained in:
committed by
GitHub
parent
632f6068c4
commit
0a252e5827
@@ -85,21 +85,20 @@ export default function LinkSurvey({
|
||||
}
|
||||
}, []);
|
||||
|
||||
const [hiddenFieldsRecord, setHiddenFieldsRecord] = useState<Record<string, string | number | string[]>>();
|
||||
const hiddenFieldsRecord = useMemo<Record<string, string | number | string[]> | null>(() => {
|
||||
const fieldsRecord: Record<string, string | number | string[]> = {};
|
||||
let fieldsSet = false;
|
||||
|
||||
useEffect(() => {
|
||||
survey.hiddenFields?.fieldIds?.forEach((field) => {
|
||||
// set the question and answer to the survey state
|
||||
const answer = searchParams?.get(field);
|
||||
if (answer) {
|
||||
setHiddenFieldsRecord((prev) => {
|
||||
return {
|
||||
...prev,
|
||||
[field]: answer,
|
||||
};
|
||||
});
|
||||
fieldsRecord[field] = answer;
|
||||
fieldsSet = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Only return the record if at least one field was set.
|
||||
return fieldsSet ? fieldsRecord : null;
|
||||
}, [searchParams, survey.hiddenFields?.fieldIds]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user