How Do I remove Form outline From JavaScript Multi-Select Form

abiodunajai 396 Reputation points
2025-02-05T11:35:25.59+00:00

Please I would like to remove form outline around multi-select form as shown below mark in red. The user get confused thinking they should add the email on the To: and Cc: 2nd Form rows rather than the Add new (To and Cc) 1st Form rows.

EmailNotification popup

The result expected should be as shown in the image below

Email multiselectSample

You will notice that there is no border/outline around the already selected names underline in red above. That is the result I love to achieve.

I have tried using the HTML style below but to no avail.

style="outline: none"

My HTML script

	<div class="row">
		<div class="col-md-12 col-sm-8 col-xs-12 col-xs-offset-0">
			<div id="claimNotificationMailDialog" tabindex="-1" role="dialog" aria-labelledby="claimNotificationMailLabel" aria-hidden="true" class="modal fade" data-backdrop="static" data-keyboard="false">
				<div class="modal-dialog modal-lg" style="height:25vh; max-height:25vh; width:130vh; max-width:130vh; overflow-y: initial !important">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
							<h4 class="modal-title" id="claimNotificationMailLabel">Insurer Notification Email Selection</h4>
						</div>
                        <div class="modal-body">
                            <div class="row">
                                <div class="col-md-12 col-sm-12 col-xs-12">
                                    <div class="form-group">
                                        @Html.Label("Add new(To)", htmlAttributes: new { @class = "control-label col-md-2" })
                                        <div class="col-md-8">
                                            <input type="text" id="addNewEmailInput" class="form-control input-sm shadow-none" value="" />
                                        </div>
                                        <div class="col-md-2">
                                            <button id="addNewEmailBtn" type="button" class="btn btn-primary btn-sm" onclick="addNewItemToList('addNewEmailInput');">Add</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-12 col-sm-12 col-xs-12">
                                    <div class="form-group">
                                        @Html.Label("To:", htmlAttributes: new { @class = "control-label col-md-2" })
                                        <div class="col-md-8">
                                            @Html.DropDownListFor(m => m.SelectedNotificationMails, new MultiSelectList(Model.SelectableNotificationMails, "KeyID", "KeyDescription", Model.SelectedNotificationMails), new { @multiple = "multiple", placeholder = "Select..." })
                                            @Html.ValidationMessageFor(model => model.SelectableNotificationMails, "", new { @class = "text-danger" })
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <br />
                            <div class="row">
                                <div class="col-md-12 col-sm-12 col-xs-12">
                                    <div class="form-group">
                                        @Html.Label("Add new(Cc)", htmlAttributes: new { @class = "control-label col-md-2" })
                                        <div class="col-md-8">
                                            <input type="text" id="addNewCcEmailInput" class="form-control input-sm shadow-none" value="" />
                                        </div>
                                        <div class="col-md-2">
                                            <button id="addNewCcEmailBtn" type="button" class="btn btn-primary btn-sm" onclick="addNewCcItemToList('addNewCcEmailInput');">Add</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-12 col-sm-12 col-xs-12">
                                    <div class="form-group">
                                        @Html.Label("Cc:", htmlAttributes: new { @class = "control-label col-md-2" })
                                        <div class="col-md-8">
                                            @Html.DropDownListFor(m => m.SelectedCCNotificationMails, new MultiSelectList(Model.SelectableCCNotificationMails, "KeyID", "KeyDescription", Model.SelectedCCNotificationMails), new { @multiple = "multiple", placeholder = "Select..."})
                                            @Html.ValidationMessageFor(model => model.SelectableCCNotificationMails, "", new { @class = "text-danger" })
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
						<div class="modal-footer" style="background: #e8c8d8; border-radius:8px">
							<a class="btn btn-primary" id="cancelButton" data-dismiss="modal">Cancel</a>
							<input name="actionType" type="submit" class="btn btn-danger" value="Notify Insurer" />
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

JavaScript

		function validateEmail(email) {

			return /^[\w-]+(\.[\w-]+)*@@([a-z0-9-]+(\.[a-z0-9-]+)*?\.[a-z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?$/.test(email);
		}

		function addNewItemToList(ctrl) {

			var value = document.getElementById(ctrl).value;
			if (value == null || value == "") {
				BootstrapDialog.alert("Please enter a valid email address");
				return;
			}
			var list = value.split(",");

			for (i = 0; i < list.length; i++) {
				if (!validateEmail(list[i])) {
					BootstrapDialog.alert("Please enter a valid email address (" + list[i] + ")");
					return;
				} 
			}

			for (i = 0; i < list.length; i++) {
				var v2 = list[i];
				var key = v2.replaceAll("@@", "___").replaceAll(".", "__");
				$('#SelectedNotificationMails').append("<option value=\"" + key + "\">" + v2 + "</option>");
				$("#SelectedNotificationMails option[value=" + key + "]").attr('selected', true);

				$('#SelectedNotificationMails').trigger('chosen:updated');
				document.getElementById(ctrl).value = "";
			}			
		}

		function addNewCcItemToList(ctrl) {

			var value = document.getElementById(ctrl).value;
			if (value == null || value == "") {
				BootstrapDialog.alert("Please enter a valid email address");
				return;
			}
			var list = value.split(",");

			for (i = 0; i < list.length; i++) {
				if (!validateEmail(list[i])) {
					BootstrapDialog.alert("Please enter a valid email address (" + list[i] + ")");
					return;
				}
			}

			for (i = 0; i < list.length; i++) {
				var v2 = list[i];
				var key = v2.replaceAll("@@", "___").replaceAll(".", "__");
				$('#SelectedCCNotificationMails').append("<option value=\"" + key + "\">" + v2 + "</option>");
				$("#SelectedCCNotificationMails option[value=" + key + "]").attr('selected', true);

				$('#SelectedCCNotificationMails').trigger('chosen:updated');
				document.getElementById(ctrl).value = "";
			}	
		}

Thanking you in anticipation of your kind response.

Best regards,

Lawrence

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,590 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,277 questions
ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
370 questions
0 comments No comments
{count} votes

Accepted answer
  1. MohaNed Ghawar 75 Reputation points
    2025-02-05T17:55:28.1266667+00:00
    1. 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>

    1. 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;"

    })

    1. 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

    });

    });

    });

    1. 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 -->


1 additional answer

Sort by: Most helpful
  1. MohaNed Ghawar 75 Reputation points
    2025-02-05T11:41:28.9866667+00:00

    I'll provide you with the CSS code that you can add to your project's stylesheet or within a <style> tag in your view:

    /* Remove border from multi-select containers */

    .chosen-container .chosen-choices,

    .select2-container .select2-selection--multiple {

    border: none !important;

    box-shadow: none !important;

    background-image: none !important;

    }

    /* Remove border from selected items */

    .chosen-container .chosen-choices li.search-choice,

    .select2-container .select2-selection--multiple .select2-selection__choice {

    border: none;

    box-shadow: none;

    background: #f3f3f3;

    padding: 5px 20px 5px 10px;

    border-radius: 3px;

    }

    /* Remove outline on focus */

    .chosen-container-active .chosen-choices,

    .select2-container--focus .select2-selection--multiple {

    border: none !important;

    box-shadow: none !important;

    }

    /* Style the input field */

    .chosen-container .chosen-choices input[type="text"],

    .select2-container .select2-search__field {

    border: none !important;

    outline: none !important;

    box-shadow: none !important;

    }

    1. In your view file, add it within a <style> tag in the <head> section: <style> /* Paste the CSS here */ </style>
    2. In your site's main CSS file (often found in Content/Site.css or similar)
    3. Create a new CSS file specifically for your email notification styles and reference it in your layout or view

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.