Closed glitchedmob closed 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
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
No problem! Thanks for fixing this issue!
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.