Dolphiq / craft3-iconpicker

Craft plugin that provides a new field type that offers end users an easy way to pick an icon from a .woff or .ttf font file. You can easily use ionicons or font awesome icons or any other compatible font file.
MIT License
16 stars 11 forks source link

Icon Picker does not respond when in Matrix Field #11

Closed jeffaglenn closed 6 years ago

jeffaglenn commented 6 years ago

When the Icon Picker field is within a Matrix clicking the button does nothing. The issue is discussed a little here https://github.com/Dolphiq/craft3-iconpicker/issues/7 but the title does not reflect the discussion.

jeffaglenn commented 6 years ago

Any idea on this?

I have found a work-around but it's not great:

  1. Add the icon field to a matrix block
  2. When creating/editing the entry add the matrix row with the icon field but do not add the icon
  3. Save the entry (or save as draft) with an empty icon field
  4. Edit the entry again and the icon button should work
glitchedmob commented 6 years ago

I'm guessing the problem is that when icon picker is added to the DOM via a Matrix block the code in src/resources-app/js/field.js isn't rerun, so the click event listener never get's attached.

Luuc15 commented 6 years ago

Thank you for pointing this out and glitchedmob thanks for making a solution.

I looked at the solution and because of it i found the actual problem.

The problem was that the field script tried to add an on click event handler to the iconpicker button that has to open the modal. Only this button does not yet exist when using the field in a matrix field.

I altered the script and it now works correctly. So no further need to make it a garnish class and call the class separately. Also the field scripts add's a uniq id to the buttons parent already so that is not necessary any more.

The changed code is in the newest release now. https://github.com/Dolphiq/craft3-iconpicker/releases/tag/1.0.5

jeffaglenn commented 6 years ago

Awesome, thank you!