Question T15190
Visible to All Users

Programatically set the focus on a particular question Not working

created a year ago

Hi team!
The following solution does not work for me when I wish to programatically focus on a particular question in survey runner.

1 ) Using survey.getQuestionByName("yourQuestionName).focus();
https://github.com/surveyjs/survey-creator/issues/382

2)Using survey focusQuestion method
focusQuestionmethod

Answers approved by surveyjs Support

created a year ago

Hello Nikhil,
Both of these functions are used to focus a question. However, if you wish to focus a specific question at a form's startup, I may recommend that you introduce a slight delay to ensure that a form is rendered: View CodeSandbox.

SurveyComponent.jsx

JavaScript
import React from "react"; import { Model } from "survey-core"; import { Survey } from "survey-react-ui"; import "survey-core/defaultV2.min.css"; import "./index.css"; import { json } from "./json"; function SurveyComponent() { const survey = new Model(json); setTimeout(() => { survey.focusQuestion("question6"); }, 100); survey.onComplete.add((sender, options) => { console.log(JSON.stringify(sender.data, null, 3)); }); return <Survey model={survey} />; } export default SurveyComponent;

Please let me know if you have any further questions.

    Show previous comments (5)

      Hello Nikhil,
      Thank you for the update. May I ask you to share a demo reproducing the described survey configuration?

      Thanks

        Hi Jane,
        It is issue with only custom widget , focus not setting for custom widget.

          Hello Nikhil,
          I would greatly appreciate it if you could share a reproducible demo for research. I believe this will save time for us both.

          Thank you