Chips are not returned by $('.chips-initial').mate


Topic: Chips are not returned by $('.chips-initial').materialChip('data');

Lundberg pro premium asked 5 years ago

Expected behavior According to the documentation the JS code

$('.chips-initial').materialChip('data');

returns the data, i.e. the chips in an array. This worked as documented in 4.4. In 4.8.9 however, the above code doesn't return the data as expected.

Actual behavior The code snippet returns something else, looks like a higher JS object.

NOTE the same goes for $('.chips-initial').materialChip('options');

Resources (screenshots, code snippets etc.)

See snippet https://mdbootstrap.com/snippets/jquery/lundberg/1183860/ - inspect the console after snippet has run.


Magdalena Dembna staff premium answered 5 years ago

Hi, I will report this issue to our jQuery team. In the meantime, you can try using data() method - it will return an object and one of its keys is chips which may be a solution to your problem:

$('.chips-initial1').materialChip({data:[{tag:'asd'}]});
const data = $('.chips-initial1').data();

console.log(data.chips);

Kind regards, Magdalena


Lundberg pro premium answered 5 years ago

Hi,

thank you for your reply. Indeed, your proposed solution is a good one. By rewriting my chip handling to use the array returned by .data().chips instead, I get my old code to work as expected.

As such I don't mind if the fix for this issue is a fix in the documentation, or in the code. The $('.chips-initial1').data(); syntax is very clean and clear.

Best regards,

--Ville


Magdalena Dembna staff premium commented 5 years ago

I have already created a task for our jQuery team to fix this issue/documentation. Kind regards, Magdalena


Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Resolved

Specification of the issue
  • User: Pro
  • Premium support: Yes
  • Technology: MDB jQuery
  • MDB Version: 4.8.9
  • Device: Macbook Pro
  • Browser: Chrome
  • OS: MacOs
  • Provided sample code: No
  • Provided link: Yes
Tags