Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to trigger the adding of a survey question via an external element #378

Closed
leksinteractive opened this issue Jul 17, 2018 · 5 comments · Fixed by #5882
Closed

Ability to trigger the adding of a survey question via an external element #378

leksinteractive opened this issue Jul 17, 2018 · 5 comments · Fixed by #5882
Labels

Comments

@leksinteractive
Copy link
Contributor

Are you requesting a feature, reporting a bug or ask a question?

Question to see if there's a way to do this currently, or if there are plans to implement something like it in the future.

At the moment when building a survey the toolbox seems to be the only way to add a question to the svd_questions_editor panel. I have a requirement to trigger the addition of a question from an external custom element.

To be more specific I have a custom form which should contain a standard select dropdown with a few different question types. When the user selects a question type this will trigger the addition of that question type to the survey editor which is also part of the original form (but with the toolbox hidden in this case)

I couldn't find anything in the documentation along these lines, but maybe I missed it.

Thanks,
Aleks

@andrewtelnov
Copy link
Member

@leksinteractive There are two ways of doing it.

  1. You may handle onQuestionAdded event
  2. You have a toolbox item, for example a panel, with several questions in it, by using editor.toolbox.addItem function. Here is the documentation about toolbox customization

Thank you,
Andrew

@leksinteractive
Copy link
Contributor Author

leksinteractive commented Jul 17, 2018

Thanks for the quick reply @andrewtelnov.

Yeah I saw the toolbox customization example, but in my case I don't deal with the toolbox at all. Basically I need a way to trigger an event to add the question to the survey itself (not the toolbox), so triggered from an external element totally independent of any surveyjs elements.

Something like this would be ideal:

var editor = new SurveyEditor.SurveyEditor("editorElement", editorOptions);
editor.addQuestion(questionDefinitionJson); // this could be called anywhere externally

Hope that makes sense.

@andrewtelnov
Copy link
Member

@leksinteractive you may use onQuestionAdded event.
You may access editor.survey property to get the instance of the editing survey. So you may add/delete/modify elements in this survey as you want.

Thank you,
Andrew

@andrewtelnov
Copy link
Member

@leksinteractive To add a new text question, you may use the following code:
editor.survey.currentPage.addNewQuestion("text", "myQuestionName");

Thank you,
Andrew

@leksinteractive
Copy link
Contributor Author

Awesome, thanks @andrewtelnov, that's what I was after 👍

tsv2013 pushed a commit that referenced this issue Sep 12, 2024
OlgaLarina pushed a commit that referenced this issue Sep 24, 2024
* Resolved #378 - Improving page placeholders

* Work for surveyjs/private-tasks#378 - react component and placeholder styles refactoring

* Work for surveyjs/private-tasks#378 - finished react component and implemented placeholder for ko

* Work for surveyjs/private-tasks#378 - implemented tab placeholders in Vue

* Work for surveyjs/private-tasks#378 - implemented tab placeholders in Angular

* Updated etalons

* Update etalons

* Update etalons

* Updated v-test

* Fixed placeholder texts

* Fixed Mike remarks

* Fixed placeholder title tests

* Fixed placeholder paddings

* Updated etalons

* Updated etalon

* Updated etalons

* Updated etalons

* Fixed react vr-tests

* Try to fix vr-tests

* Fixed vr-tests in ko

---------

Co-authored-by: tsv2013 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants