Is it a good user experience to prevent user from deselecting an item from a dropdown if it is required in a form?
Before I ask my question, I feel like I need to provide some context.
The application that I'm working with has a form for executing queries. This form has the following components:
inputs and textareas - native html elements that use the native constraint form validation api that the browser provides.
Single and multi select dropdowns - These are custom select components and do not use the native select html tag that browser provides and need their own form validation mechanism.
Each field in the form is either required or optional(The number of fields that are required or optional depends on how the query was created in the server. There could be more optional fields than required and vice versa).
On top of that, each select dropdown can very well have a default option(s) that is/are selected when the form is rendered i.e option(s) that is/are programmatically chosen.
Single Select Dropdown:
if it is not required, there should be a blank/empty item added to the list. (This is not sent when a query is executed).
if there is a defaultValue, select it; otherwise, select the first item in the list (either 'blank' if not required or 1st choice - so that we satisfy the required constraint)
Multi Select Dropdown:
if a parameter is required and there is no defaultValue, select all items in the list (default to "select all").
if a parameter is not required and there is no defaultValue, unselect/clear all items (default to "select none").
With all of that context, I'll now get into my main question.
For dropdowns that are required, is it to intrusive or restrictive to prevent the user from having no options selected to stop them from accidentally submitting a query that would 100% fail? I would still allow the user to deselect options from the dropdown assuming deselecting that option still leaves you with at least one option selected.
Of course, if they try to deselect from a dropdown with only one option selected, a popup message, hint etc would render and inform the user that this field cannot be left empty and would suggest them to replace this option with another one.
Obviously for dropdowns that are not required they can leave it empty or add/deselect however many options they want.
What do you guys think about this? Would this be a good validation mechanism to add to my dropdown components when they are required(both single and multi-select)?