Skip to content

Commit 49cabd7

Browse files
readme file and the object passed to event updated
1 parent e861ea8 commit 49cabd7

File tree

4 files changed

+53
-24
lines changed

4 files changed

+53
-24
lines changed

README.md

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,53 @@ Once you it install, you can import the `SurveyBuilder` by
1717
`import SurveyBuilder from 'SurveyBuilder';`
1818

1919
*Step 2:*
20-
We are using [this JSON](https://github.com/FissionHQ/vue-survey-builder/blob/master/src/survey-builder.json) to build any type of question. Depending on the type of question, only few keys are used in the whole JSON.
20+
Then you can use it in your vue component like this
21+
22+
`<SurveyBuilder :options="sampleQuestion" />`
23+
24+
Here `sampleQuestion` can be the json, which is [here](https://github.com/FissionHQ/vue-survey-builder/blob/master/src/survey-builder.json)
25+
26+
This is used to create a new question.
2127

2228
*Step 3:*
29+
We are using [this JSON](https://github.com/FissionHQ/vue-survey-builder/blob/master/src/survey-builder.json) to build any type of question. Depending on the type of question, only few keys are used in the whole JSON.
30+
31+
It emits an event called `add-update-question` with a question object and the type
32+
`this.$root.$emit('add-update-question', question);`
33+
34+
In your component, keep track of this event to capture it
35+
````
36+
mounted() {
37+
this.$root.$on('add-update-question', question => {
38+
window.console.log(question);
39+
});
40+
},
41+
````
42+
When you get the object, you can cross check for the `id`, in 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 the question to the list of questions.
43+
You can refer the sample code in the [demo repository](https://github.com/rajeshwarpatlolla/vue-survey-builder-test/blob/master/src/components/TestSurveyBuilder.vue#L30)
44+
45+
*Step 4:*
46+
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 to show the list of questions, which will be available in the [src folder](https://github.com/FissionHQ/vue-survey-builder/blob/master/src/QuestionsView.vue) itself. Please use it in case, if you want to show the questions added.
2347

48+
In the next version, this component will be available as part of the vue-survey-builder itself. Refer demo code [here](https://github.com/rajeshwarpatlolla/vue-survey-builder-test/blob/master/src/components/TestSurveyBuilder.vue#L5)
49+
50+
You can use it like
51+
52+
`<QuestionsView :questions="questionsList" :readOnly="true" />`
53+
54+
- `questions` is a property which takes an array of questions.
55+
56+
- `readOnly` is used to make the whole component editable or non editable, based on the value we pass. It takes true or false.
57+
58+
### Supported Question types
59+
- BOOLEAN
60+
- SINGLE_CHOICE
61+
- MULTI_CHOICE
62+
- SCALE
63+
- NUMBER
64+
- TEXT
65+
- DATE
66+
- TIME
2467

2568
### Keys of the JSON
2669
- **id** : This is a unique field, which will be created dynamically for every qiestion. This field is required for all type of questions.
@@ -40,16 +83,6 @@ We are using [this JSON](https://github.com/FissionHQ/vue-survey-builder/blob/ma
4083
- **units** : This represents the units to be shown. This field will be used for `NUMBER` type of questions.
4184
- **options** : This represents the options of question. This field is used by `SINGLE_CHOICE` and `MULTI_CHOICE` questions.
4285

43-
### Supported Question types
44-
- BOOLEAN
45-
- SINGLE_CHOICE
46-
- MULTI_CHOICE
47-
- SCALE
48-
- NUMBER
49-
- TEXT
50-
- DATE
51-
- TIME
52-
5386
### Versions
5487
#### 0.1.0
5588
This version is the initial official release of this component. It has all the required functionalities to build the surveys using vue.js
@@ -66,4 +99,4 @@ This version is the initial official release of this component. It has all the r
6699
[Fission Labs](http://fissionlabs.com/)
67100

68101
### LICENSE
69-
Please read it [here]()
102+
Please read it [here](https://github.com/FissionHQ/vue-survey-builder/blob/master/LICENSE.md)

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
"description": "A survey builder component for vue.js applications",
55
"main": "src/SurveyBuilder.vue",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1",
8-
"build": "NODE_ENV=production webpack --progress --hide-modules",
9-
"dist": "webpack --progress --hide-modules --config webpack.build.js && NODE_ENV=production webpack --progress --hide-modules --config webpack.build.min.js"
7+
"test": "echo \"Error: no test specified\" && exit 1"
108
},
119
"repository": {
1210
"type": "git",

src/SurveyBuilder.vue

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,13 @@
9090
<div class="" v-if="selectedType === 'SINGLE_CHOICE'">
9191
<div class="vsb-choices-text">Answer Choices</div>
9292
<div class="" v-for="(option, index) in question.options" :key="index">
93-
<div class="">
94-
<input type="text" class="" placeholder="Enter an answer choice" v-model="option.body">
95-
</div>
96-
<div class="">
97-
<button class="" v-on:click="deleteQuestionOptionItem(question.options, index)" v-if="index > 1">Remove</button>
93+
<div class="clear-both">
94+
<input type="text" class="width-90 float-left" placeholder="Enter an answer choice" v-model="option.body">
95+
<button class="vsb-btn-link color-red width-10 mt-10" v-on:click="deleteQuestionOptionItem(question.options, index)" v-if="index > 1">Remove</button>
9896
</div>
9997
</div>
100-
<div class="vsb-add-answer-btn vsb-btn-link color-blue">
101-
<a v-on:click="addAnotherAnswer()">Add another answer</a>
98+
<div class="display-block">
99+
<button class="vsb-btn-link color-blue" v-on:click="addAnotherAnswer()">Add another answer</button>
102100
</div>
103101
</div>
104102
<div class="" v-if="selectedType === 'TEXT'">
@@ -229,7 +227,7 @@ export default {
229227
*/
230228
saveQuestion(question) {
231229
question.id = question.id ? question.id : this.getGUID(); // eslint-disable-line
232-
this.$root.$emit('add-update-question', { question, operation: 'save' });
230+
this.$root.$emit('add-update-question', question);
233231
this.question = { type: 'DEFAULT' };
234232
},
235233

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ if (process.env.NODE_ENV === 'production') {
4747
new webpack.optimize.OccurenceOrderPlugin()
4848
]
4949
} else {
50-
}
50+
}

0 commit comments

Comments
 (0)