Select and Multiselect Validation

Topic: Select and Multiselect Validation

matis asked 3 years ago

I can't validate select nor multiselect with standard validation JS (input, datepicker work fine)

<!-- Game type -->
<div class="md-form">
    <i class="fas fa-plus prefix"></i>
    <select id="type" class="mdb-select colorful-select dropdown-success mx-auto"
            name="type" required>
        <option value="" selected>Choose type of game</option>
        <option value="type1"
        <option value="type2"
        <option value="type3"
        <span class="invalid-feedback" role="alert">
            <strong class="ml-5">Choose type</strong>

<!-- Game category -->
<div class="md-form">
    <i class="fas fa-plus prefix"></i>
    <select id="category" class="mdb-select colorful-select dropdown-success mx-auto"
            name="category[]" multiple>
        <option value="" selected>Choose categories</option>
        <option value="cat1" data-type="cat-type"
        <option value="cat2" data-type="cat-type"
        <option value="cat3" data-type="cat-type"
        <span class="invalid-feedback" role="alert">
            <strong class="ml-5">Choose at least two</strong>

Could I ask for help with that? I assumed that will work "out of the box", but it doesn't, or I do something wrong?

Piotr Glejzer staff commented 3 years ago

did you use this example? it's working fine in snippets

fmaeseele pro commented 3 years ago

Hi, The materialSelect validation described in the doc is totally useless. In a normal use case, the form would probably be inside a modal dialog, so you have to trigger a form reset before displaying the modal, then it calls the init of the material select, and the component doesn't work anymore: no placeholder displayed, no save button displayed, etc... You should do better testing before releasing code, or at least look to integrate the fixes some customers provide. Do remember that in most cases, your examples are out of use cases, so it may help using it, but do not reflect how your components are used.

Piotr Glejzer staff commented 3 years ago

For this moment we don't have a better solution for that. I added the task to make a better approach in the future. Have a nice day.

Kneidels pro commented 3 years ago

Have there been any improvements on this yet?

Sebastian Kaczmarek staff pro premium commented 3 years ago

I'm afraid I don't fully understand OP's problem. As shown in e.g. this Snippet: the validation seems to work fine in the latest 4.9.0 version. Is that what you are looking for? Or is it something else (try to describe current and expected behavior)?

Please insert min. 20 characters.


Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.



Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.7.6
  • Device: Laptop
  • Browser: Firefox
  • OS: Ubuntu
  • Provided sample code: No
  • Provided link: No