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

Fix issue with iconpicker not working in a matrix field #13

Closed glitchedmob closed 6 years ago

glitchedmob commented 6 years ago

This PR fixes #7 and #11

As of right now this code does work, although I don't know a lot about Garnish (mainly because there isn't much in terms of documentation), so there could definitely be some better ways to approach this. I'm open to suggestions.

Another thing I'll mention is that src/views/main/_field.php is written with raw PHP. From what i've seen in the Craft codebase it's better to use twig for this. It could potentially clean up that file and allow us to add that script tag using Craft's {% js %} template tag.

glitchedmob commented 6 years ago

I think I've finally figured this out. Would love it if someone could review and provide feedback or merge it in

Luuc15 commented 6 years ago

Hi glitchedmob,

Thank you for taking the time to search for a solution. I looked at your 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.

Still thanks for finding a solution, it pointed me in the right direction of solving the problem.

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

glitchedmob commented 6 years ago

No problem! Thanks for fixing this issue!