Topic: Why doesn't autocomplete accept { value: '1', label: 'Option 1' }, like Material Select?

rctoone pro asked 6 years ago


Why doesn't autocomplete accept { value: '1', label: 'Option 1' }, like Material Select? I don't understand why you would make an autocomplete component that doesn't support your Material Select Data Models?  The inconsistency between components is becoming a major pain.... { value: '1', label: 'Option 1' }

I made some modifications to mdb.js First, your object must be in the format [{value, text}] Example: [{Value: 1, Text: “AAA”}, {Value: 2, Text: “BBB”}, …] Find the function $.fn.mdb_autocomplete in mdb.js (in my case it was the line 27502) I made change in the for the keyup event: for (var item in data) { // check if item contains value that we’re looking for if (data[item].Text.toLowerCase().indexOf(q.toLowerCase()) !== -1) { //row changed var option = $(” + data[item].Text + ”); //row changed $autocomplete.append(option); } } And also in the event click li, where I added the line below: // Set input value after click $input.val($(this).text()); // Set input data-value $input.attr(“data-value”, $(this).val()); //row add Now I can read the data-value attribute of the input. It is a solution that helped me, and I hope I have helped.

Dawid Adach pro answered 6 years ago


Dear rctoone, that's good point. I will ad this to our todo list, we will change it in future releases.

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