Skip to content

Commit 42bffa5

Browse files
committed
Added different activation types for prettycheckbox custom widget
1 parent 5259e47 commit 42bffa5

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/pretty-checkbox.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function init(Survey) {
1515
}
1616
},
1717
name: "pretty-checkbox",
18+
activatedBy: "property",
1819
widgetIsLoaded: function() {
1920
for (var i = 0; i < document.styleSheets.length; i++) {
2021
var href = document.styleSheets[i].ownerNode["href"];
@@ -26,8 +27,31 @@ function init(Survey) {
2627
},
2728
htmlTemplate: "<fieldset></fieldset>",
2829
isFit: function(question) {
29-
var type = question.getType();
30-
return type === "radiogroup" || type === "checkbox"; // || type === "matrix";
30+
var isFitByType =
31+
question.getType() === "radiogroup" ||
32+
question.getType() === "checkbox";
33+
if (widget.activatedBy === "property")
34+
return question["renderAs"] === "prettycheckbox" && isFitByType;
35+
if (widget.activatedBy === "type") return isFitByType;
36+
return false;
37+
},
38+
activatedByChanged: function(activatedBy) {
39+
if (!this.widgetIsLoaded()) return;
40+
widget.activatedBy = activatedBy;
41+
Survey.JsonObject.metaData.removeProperty("radiogroup", "renderAs");
42+
Survey.JsonObject.metaData.removeProperty("checkbox", "renderAs");
43+
if (activatedBy === "property") {
44+
Survey.JsonObject.metaData.addProperty("radiogroup", {
45+
name: "renderAs",
46+
default: "standard",
47+
choices: ["standard", "prettycheckbox"]
48+
});
49+
Survey.JsonObject.metaData.addProperty("checkbox", {
50+
name: "renderAs",
51+
default: "standard",
52+
choices: ["standard", "prettycheckbox"]
53+
});
54+
}
3155
},
3256
isDefaultRender: false,
3357
afterRender: function(question, el) {

0 commit comments

Comments
 (0)