Skip to content

Commit 4febb7d

Browse files
committed
Added bootstrap-slider custom widget prototype (work for #13 - widget request "bootstrap slider")
1 parent 4c0c5d9 commit 4febb7d

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"private": true,
1010
"devDependencies": {
11+
"bootstrap-slider": "^10.0.0",
1112
"clean-webpack-plugin": "^0.1.17",
1213
"copy-webpack-plugin": "^4.1.1",
1314
"easy-autocomplete": "^1.3.5",

src/bootstrap-slider.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
var Slider = require("bootstrap-slider");
2+
3+
function init(Survey) {
4+
var widget = {
5+
name: "bootstrap-slider",
6+
title: "Bootstrap Slider",
7+
iconName: "icon-bootstrap-slider",
8+
widgetIsLoaded: function() {
9+
return typeof Slider != "undefined";
10+
},
11+
isFit: function(question) {
12+
return question.getType() === "bootstrapslider";
13+
},
14+
htmlTemplate: "<div></div>",
15+
activatedByChanged: function(activatedBy) {
16+
Survey.JsonObject.metaData.addClass("bootstrapslider", [], null, "empty");
17+
Survey.JsonObject.metaData.addProperties("bootstrapslider", [
18+
{
19+
name: "step:number",
20+
default: 1
21+
},
22+
{
23+
name: "rangeMin:number",
24+
default: 0
25+
},
26+
{
27+
name: "rangeMax:number",
28+
default: 100
29+
}
30+
]);
31+
},
32+
afterRender: function(question, el) {
33+
var inputEl = document.createElement("input");
34+
inputEl.id = question.id;
35+
inputEl.type = "text";
36+
inputEl.setAttribute("data-slider-id", question.name + "_" + question.id);
37+
inputEl.setAttribute("data-slider-min", question.rangeMin);
38+
inputEl.setAttribute("data-slider-max", question.rangeMax);
39+
inputEl.setAttribute("data-slider-step", question.step);
40+
inputEl.setAttribute("data-slider-value", question.value);
41+
el.appendChild(inputEl);
42+
var slider = new Slider(inputEl, {});
43+
44+
slider.on("change", function(valueObj) {
45+
question.value = slider.getValue();
46+
});
47+
var updateValueHandler = function() {
48+
slider.setValue(question.value);
49+
};
50+
question.bootstrapSlider = slider;
51+
question.valueChangedCallback = updateValueHandler;
52+
},
53+
willUnmount: function(question, el) {
54+
question.bootstrapSlider.destroy();
55+
question.bootstrapSlider = null;
56+
}
57+
};
58+
59+
Survey.CustomWidgetCollection.Instance.addCustomWidget(widget, "customtype");
60+
}
61+
62+
if (typeof Survey !== "undefined") {
63+
init(Survey);
64+
}
65+
66+
export default init;

src/surveyjs-widgets.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export { default as sortablejs } from "./sortablejs.js";
1111
export { default as ckeditor } from "./ck-editor.js";
1212
export { default as autocomplete } from "./easy-autocomplete.js";
1313
export { default as prettycheckbox } from "./pretty-checkbox.js";
14+
export { default as bootstrapslider } from "./bootstrap-slider.js";

webpack.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ var widgets = [
3333
"nouislider",
3434
"ck-editor",
3535
"easy-autocomplete",
36-
"pretty-checkbox"
36+
"pretty-checkbox",
37+
"bootstrap-slider"
3738
];
3839

3940
var dependencies = {
@@ -47,7 +48,8 @@ var dependencies = {
4748
inputmask: "^3.3.10",
4849
"jquery-bar-rating": "^1.2.2",
4950
"easy-autocomplete": "^1.3.5",
50-
"pretty-checkbox": "^3.0.3"
51+
"pretty-checkbox": "^3.0.3",
52+
"bootstrap-slider": "^10.0.0"
5153
};
5254

5355
var entry = {};

0 commit comments

Comments
 (0)