Skip to content

Commit 6825e11

Browse files
committed
Added display mode for the image picker custom widget - #45 - Display mode causes imagepicker to not show up at all
1 parent f7b981e commit 6825e11

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/image-picker.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,38 @@ function init(Survey, $) {
4949
});
5050
},
5151
afterRender: function(question, el) {
52-
var $el = $(el).is("select") ? $(el) : $(el).find("select");
53-
var options = $el.find("option");
5452
var choices = question.choices;
53+
if (question.isReadOnly) {
54+
$el = $(el);
55+
var $ul = $('<ul class="thumbnails image_picker_selector"></ul>');
56+
$el.empty();
57+
$el.append($ul);
58+
for (var i = 0; i < choices.length; i++) {
59+
var selected = question.value === choices[i].value ? "selected" : "";
60+
$ul.append(
61+
'<li><div class="thumbnail ' +
62+
selected +
63+
'"><img class="image_picker_image" src="' +
64+
choices[i].imageLink +
65+
'"></div></li>'
66+
);
67+
}
68+
} else {
69+
var $el = $(el).is("select") ? $(el) : $(el).find("select");
70+
var options = $el.find("option");
5571

56-
for (var i = 1; i < options.length && i - 1 < choices.length; i++) {
57-
$(options[i]).data("imgSrc", choices[i - 1].imageLink);
58-
options[i].selected = question.value == options[i].value;
59-
}
60-
$el.imagepicker({
61-
hide_select: true,
62-
show_label: question.showLabel,
63-
selected: function(opts) {
64-
question.value = opts.picker.select[0].value;
72+
for (var i = 1; i < options.length && i - 1 < choices.length; i++) {
73+
$(options[i]).data("imgSrc", choices[i - 1].imageLink);
74+
options[i].selected = question.value == options[i].value;
6575
}
66-
});
76+
$el.imagepicker({
77+
hide_select: true,
78+
show_label: question.showLabel,
79+
selected: function(opts) {
80+
question.value = opts.picker.select[0].value;
81+
}
82+
});
83+
}
6784
},
6885
willUnmount: function(question, el) {
6986
var $el = $(el).find("select");

0 commit comments

Comments
 (0)