Topic: mdb-select validation support

SJMAZY@GMAIL.COM pro asked 6 years ago


Hi Guys,I am a pro user and am trying to validate mdb-select. I have played around with the below code: $('.mdb-select').on('change', function(e){console.log(e.target.options[e.target.selectedIndex].value);console.log(e.target.options[e.target.selectedIndex].text);}) Are you able to provide an example on how to incorporate the above code with mdb-select field? For example lets say the field name ="test" and I want to provide an error message if nothing is selected.How would I use the above code to validate the "test" dropdown?

Jakub Strebeyko staff commented 6 years ago

Dear SJMAZY@GMAIL.COM, Could you be more specific about the mechanism of validation you're mentioning? I'm guessing you do not mean displaying an error when there's no option chosen yet. The code you provided helps identifying particular options chosen, but does not disclose the context in which you're using material dropdown, not to mention the desired behavior (i.e. trigger for error message, like pressing the submit button in your form or clicking away of dropdown menu). With Best Regards, Kuba

SJMAZY@GMAIL.COM pro commented 6 years ago

.

SJMAZY@GMAIL.COM pro answered 6 years ago


Hi Kuba, Thank you for letting me know - Im liking MDB so its a small price to pay. I did find a solution using http://parsleyjs.org/ It works perfect with mdb-select and all your other form inputs

Jakub Strebeyko staff commented 6 years ago

Hi there SJMAZY@GMAIL.COM, We're working on improving MDB everyday, but nothing makes our effort worthwhile as people enjoying using the tool. Thank you! We're happy to know that you managed to resolve the issue -- and thanks for sharing it with us all! That's the community spirit that pushes us forward. I wish you many great projects & a good day, Kuba

SJMAZY@GMAIL.COM pro answered 6 years ago


HI Kuba, Thank you for your reply – I am using mdb-select in a multi-step form. What I am trying to make happen is to display an error when there is no option chosen yet and for that to be alerted when the user presses the “next” button. I have validation errors working for every other part of the form. I can get it working also on browser-default class (which is standard dropdown). But the moment I change to mdb-select it doesnt work.

Jakub Strebeyko staff commented 6 years ago

Dear SJMAZY@GMAIL.COM, Unfortunately, currently I cannot deliver mentioned solution. When it comes to the standard HTML5 validation method through "required" attribute, it is unsupported due to the nature of the material_select function. The need for this feature is becoming more and more apparent though, so it has been added to our jQuery TODO. With Best Regards, Kuba


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: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: Yes
  • Provided link: No
Tags