I would like to transform the a list of check boxes like the screenshot below
I would like it transformed to
Here is a snippet of the HTML code:
Color of latex balloons
Here is the code I have written so far but can't seem to get it to work.
(function() { var uploadUrl = 'https://cdn.test.com/s/files/1/2642/9394/files/';
$.each($('[data-option-name="color-of-latex-balloons"] select'), function() { // make the element "chosen" (note: this is not yet fully compatible with required dropdowns) var $placeholder = $(this).find('input[value=""]'); if ($placeholder.length > 0) { $(this).attr('data-placeholder', $placeholder.text()); $placeholder.text(''); }
$(this).chosen({ width: '100%' }).on('chosen:showing_dropdown', function(e) {
// display swatches in dropdown
var $select = $(this);
var $chosenElement = $(e.currentTarget.nextSibling);
$.each($chosenElement.find('li'), function() {
var colorName = $select.find('input').eq($(this).data('value')).val();
var colorUrl = uploadUrl + colorName.toLowerCase().replace(/ /g, '-') + '.jpg';
$(this).prepend('<span style="display: inline-block; width: 15px; margin-right: 10px; background-image: url(\'' + colorUrl + '\');"> </span>');
});
}).on('change', function(e, params) {
// set the swatch when an option is chosen
var $chosenElement = $(e.currentTarget.nextSibling);
var colorName = params.selected;
var colorUrl = uploadUrl + colorName.toLowerCase().replace(/ /g, '-') + '.jpg';
$chosenElement.find('.chosen-single span').prepend('<span style="display: inline-block; width: 15px; height: 15px; margin-bottom: -3px; margin-right: 10px; background-image: url(\'' + colorUrl + '\');"> </span>');
});
}); })();
I would appreciate any help.