Back

Multi-select custom field

Description

This builds on the codeshare Stephen Bell provided for using a custom field with a select. This uses a multi-select and reads back in multiple values and resets them when the contentlet is opened.

Code

/* When page is loaded, copy the hidden field value to the dropdown, initialValues is an array after split */
                var initialValues =
$("#curriculumAssociation").val().split(',');
                var iLength = initialValues.length;
                for(var i = 0; i<iLength; i++){
                   $("#curriculumAssociation_field select
option").each(function(index){
                    if($(this).val() == initialValues[i]){
                        $(this).val(initialValues[i]).attr('selected',
'selected');
                        }
                    });