document.querySelectorAll('.dp-select2').forEach(
    function(dpSelect2) {
	var placeholderlabel = dpSelect2.getAttribute('data-placeholderlabel');
	var placeholdervalue = dpSelect2.getAttribute('data-placeholdervalue');
	var closeOnSelect = dpSelect2.getAttribute('data-close-on-select');
	var dropdownCssClass = dpSelect2.getAttribute('data-dropdown-css-class');
	var allowClear = dpSelect2.getAttribute('data-allow-clear');
	var minimumResultsForSearch = dpSelect2.getAttribute('data-minimum-results-for-search');

	var options = {};
	if(placeholderlabel || placeholdervalue) {
            options.placeholder = {};
            //options.allowClear = true;
	}
	if(allowClear) {
            options.allowClear = true;
	}
	if(placeholderlabel) {
            options.placeholder.text = placeholderlabel;
	}
	if(placeholdervalue) {
            options.placeholder.id = placeholdervalue;
	} else if(placeholderlabel) {
            options.placeholder.id = '';
	}
	if(closeOnSelect == 0) {
            options.closeOnSelect = false;
	}
	if(dropdownCssClass) {
            options.dropdownCssClass = dropdownCssClass;
	}
	if(minimumResultsForSearch != null && typeof minimumResultsForSearch != 'undefined') {
            options.minimumResultsForSearch = minimumResultsForSearch;
	}
	$(dpSelect2).select2(options);
    }
);
