This is a survey builder component for vue.js applications.
You can install the component using npm i -S vue-survey-builder
You can see the demo here
Please look at the souce code of the demo here
Step 1:
Once you install it, you can import the SurveyBuilder
as shown below
import { SurveyBuilder, SurveyBuilderJson } from 'vue-survey-builder';
Step 2: You can use it in your vue component, as shown below
<SurveyBuilder :options="SurveyBuilderJson" />
Here SurveyBuilderJson
is the json, which is used to form question object. Please take a look at it here
Depending on the type of question, only few keys are used in the whole JSON.
Step 3:
SurveyBuilder
emits an event called add-update-question
with a question object this.$root.$emit('add-update-question', question);
In your component, keep track of this event to capture the question which is added or updated
mounted() {
this.$root.$on('add-update-question', question => {
window.console.log(question);
});
},
Each question will have an id
which is a UUID field. Once you get the question object form the above event, you can check the id
of with with the list of questions you have. If the id
exists, then it means there is an update to the question, if the id
doesn't exist, then you can directly add that question to the list of questions.
You can refer the sample code in the demo repository
Step 4:
You can add your own logic in your component to show the list of question in read only and edit mode. There is a component called QuestionsView
, to show the list of questions, which is available here. Please use this component QuestionsView
in case, you want to show the list of questions added.
You can import this component as shown below
import { QuestionsView } from 'vue-survey-builder';
Once you import it, you can use it in your component as shown below
<QuestionsView :questions="questionsList" :readOnly="true" />
questions
is a property which takes an array of questions.
readOnly
is used to make the whole component editable or non editable, based on the value we pass. It takes true or false.
false
by default and will be true
only for MULTI_CHOICE
question.NUMBER
type of questions only.NUMBER
type only.NUMBER
type of questions only.NUMBER
type of questions only.DATE
type of questions.TIME
type of questions.SCALE
type of questions.TEXT
type of questions.NUMBER
type of questions.SINGLE_CHOICE
and MULTI_CHOICE
questions.This version is the initial release of this open source project. It has all the required functionalities to build the surveys using vue.js
This version exports SurveyBuilder
, QuestionsView
and SurveyBuilderJson
from index.js file.
Please read it here