- First, add this CSS in the
<head>
section or in a separate CSS file:
<style>
/* Target the specific dropdowns by their IDs */
#SelectedNotificationMails_chosen,
#SelectedCCNotificationMails_chosen {
border: none !important;
}
#SelectedNotificationMails_chosen .chosen-choices,
#SelectedCCNotificationMails_chosen .chosen-choices {
border: none !important;
background-image: none !important;
background-color: transparent !important;
box-shadow: none !important;
padding: 0 !important;
}
#SelectedNotificationMails_chosen .chosen-choices li.search-choice,
#SelectedCCNotificationMails_chosen .chosen-choices li.search-choice {
border: none !important;
background: #f3f3f3 !important;
box-shadow: none !important;
padding: 5px 20px 5px 10px !important;
margin: 3px !important;
}
/* Remove focus states */
#SelectedNotificationMails_chosen.chosen-container-active .chosen-choices,
#SelectedCCNotificationMails_chosen.chosen-container-active .chosen-choices {
border: none !important;
box-shadow: none !important;
}
</style>
- Modify your DropDownListFor to include the necessary classes and attributes:
@Html.DropDownListFor(m => m.SelectedNotificationMails,
new MultiSelectList(Model.SelectableNotificationMails, "KeyID", "KeyDescription", Model.SelectedNotificationMails),
new {
@multiple = "multiple",
@class = "chosen-select",
@data_placeholder = "Select...",
@style = "width: 100%; border: none;"
})
@Html.DropDownListFor(m => m.SelectedCCNotificationMails,
new MultiSelectList(Model.SelectableCCNotificationMails, "KeyID", "KeyDescription", Model.SelectedCCNotificationMails),
new {
@multiple = "multiple",
@class = "chosen-select",
@data_placeholder = "Select...",
@style = "width: 100%; border: none;"
})
- Add this JavaScript code after your existing JavaScript (make sure it's after jQuery and chosen.jquery.js):
$(document).ready(function() {
// Initialize Chosen with specific options
$(".chosen-select").chosen({
width: "100%",
search_contains: true,
inherit_select_classes: true
});
// Function to remove borders
function removeChosenBorders() {
$('.chosen-container .chosen-choices').css({
'border': 'none',
'box-shadow': 'none',
'background-image': 'none',
'background-color': 'transparent'
});
}
// Apply immediately
removeChosenBorders();
// Modify your existing functions
var originalAddNewItemToList = addNewItemToList;
addNewItemToList = function(ctrl) {
originalAddNewItemToList(ctrl);
removeChosenBorders();
};
var originalAddNewCcItemToList = addNewCcItemToList;
addNewCcItemToList = function(ctrl) {
originalAddNewCcItemToList(ctrl);
removeChosenBorders();
};
// Handle dynamic updates
$('.chosen-select').on('chosen:showing_dropdown chosen:hiding_dropdown chosen:updated', function() {
removeChosenBorders();
});
// Observer for dynamic changes
const observer = new MutationObserver(function(mutations) {
removeChosenBorders();
});
// Observe both select containers
$('.chosen-container').each(function() {
observer.observe(this, {
childList: true,
subtree: true,
attributes: true
});
});
});
- Make sure these scripts are included in the correct order:
<script src="/path/to/jquery.min.js"></script>
<script src="/path/to/chosen.jquery.min.js"></script>
<!-- Your custom JavaScript with the functions above -->