I am currently using validate.js to validate my form and choices.min.js as a substitute instead of using select in order for me to have a proper search bar on select. I am currently testing the choices.min.js my problem is the error message as well as the error class which is is-invalid is not adding or displaying. Kindly refer to this screenshot:
Here is my the html code:
<div class="form-group mb-3">
<div class="choices" data-type="select-one" tabindex="0" role="listbox" aria-haspopup="true" aria-expanded="false">
<div class="choices__inner">
<select class="form-control choices__input" data-trigger="" name="choices_single_default" id="choices_single_default" hidden="" tabindex="-1" data-choice="active">
<option value="" data-custom-properties="[object Object]">--</option>
</select>
<div class="choices__list choices__list--single">
<div class="choices__item choices__placeholder choices__item--selectable" data-item="" data-id="1" data-value="" data-custom-properties="[object Object]" aria-selected="true">--</div>
</div>
</div>
<div class="choices__list choices__list--dropdown" aria-expanded="false">
<div class="choices__list" role="listbox">
<div id="choices--choices_single_default-item-choice-1" class="choices__item choices__item--choice is-selected choices__placeholder choices__item--selectable is-highlighted" role="option" data-choice="" data-id="1" data-value="" data-select-text="" data-choice-selectable="" aria-selected="true">--</div>
<div id="choices--choices_single_default-item-choice-2" class="choices__item choices__item--choice choices__item--selectable" role="option" data-choice="" data-id="2" data-value="Choice 1" data-select-text="" data-choice-selectable="">Choice 1</div>
<div id="choices--choices_single_default-item-choice-3" class="choices__item choices__item--choice choices__item--selectable" role="option" data-choice="" data-id="3" data-value="Choice 2" data-select-text="" data-choice-selectable="">Choice 2</div>
<div id="choices--choices_single_default-item-choice-4" class="choices__item choices__item--choice choices__item--selectable" role="option" data-choice="" data-id="4" data-value="Choice 3" data-select-text="" data-choice-selectable="">Choice 3</div>
</div>
</div>
Here is my javascript code:
$('#signin-form').validate({
rules: {
email: {
required: true,
email: true
},
choices_single_default: {
required: true,
},
password: {
required: true
}
},
messages: {
email: {
required: 'Please enter your email address',
email: 'Please enter a valid email address'
},
choices_single_default: {
required: 'Please enter your choice'
},
password: {
required: 'Please enter your password'
}
},
errorPlacement: function(error, element) {
if (element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else if (element.hasClass('choices__input')) {
error.insertAfter(element.siblings('.choices__list--dropdown'));
} else {
error.insertAfter(element);
}
},
highlight: function(element) {
if ($(element).hasClass('choices__input')) {
$(element).siblings('.choices__list--dropdown').addClass('is-invalid');
} else {
$(element).addClass('is-invalid');
}
},
unhighlight: function(element) {
if ($(element).hasClass('choices__input')) {
$(element).siblings('.choices__list--dropdown').removeClass('is-invalid');
} else {
$(element).removeClass('is-invalid');
}
},
submitHandler: function(form) {
// ajax code
return false;
}
});
I have tried to use chat GPT to fix my problem but to no avail. I tried to read the documentation still not working.

You wrote in one of your post above "I checked there were limitations with choices.js that is why I opted for select2 instead". Because you did not delete your post, I will still answer your question if others are still looking for an answer.
You can use the choices instance to add a class to
.containerInner.element. In this example we add our own css class called.is-invalid.You can of course also use the function below to display the message when no option has been selected.
We also use the choices
passedElement.element.addEventListenerso that if the user does select an option, we can remove theis_invalidclass.Example: