Topic: How to make Mdb Multi-Select required

Tina Meadors pro asked 5 years ago


I'm using the mdb-select Multi-Select, with the Save button inside the dropdown, for the first time. I tried adding the "required" attribute to the select, but it still submits if no options are selected. What is the best way to prevent the save button from submitting if no items in the multi-select are selected?


MDBootstrap staff answered 5 years ago


Hi Tina,

button in multi-select is created to close the multi-select without submitting anything to the form. This component doesn't support your needs by default but you can write this functionality on your own. You can disable a button by adding attribute disabled and revert these changes by adding class active like we explain in our buttons docs: https://mdbootstrap.com/docs/jquery/components/buttons/ To make this work you need to set listener to the changes inside our multi-select. It can work similarly to this

$('.select-dropdown').val() ? $('.mdb-select button').attr('disabled','disabled') : $('.mdb-select button').addClass('active');

If you need additional help I am here for you.

Best Regards, Piotr



Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Answered

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.8.5
  • Device: Desktop
  • Browser: Chrome
  • OS: Windows
  • Provided sample code: No
  • Provided link: No