django-cms / djangocms-icon

django CMS Icon adds capabilities to implement Font or SVG icons as plugins into your project.
https://www.django-cms.org
Other
18 stars 18 forks source link

Multiple iconsets cause problems with the icon selector widget #9

Closed SteinRobert closed 5 years ago

SteinRobert commented 5 years ago

There is a problem with the icon selector widget using multiple icon sets.

Example:

DJANGOCMS_ICON_SETS = [
    (ICONSET, 'icon', 'SVG icons'),
    (ICONSET2, 'icon2', 'SVG icons 2'),
]

If one does select an icon from "SVG icons 2" and saves the plugin, opens it again, the wrong icon will be preselected (first of "SVG icons"). Steps to reproduce:

  1. Use following configuration:
    DJANGOCMS_ICON_SETS = [
    ('fontawesome', 'fa', 'Font Awesome'),
    (ICONSET, 'icon', 'SVG icons'),
    ]
  2. Insert an icon plugin with an icon from "SVG Icons" into a placeholder.
  3. Open the plugin again - wrong icon will be selected.
vxsx commented 5 years ago

https://github.com/divio/djangocms-icon/commit/3fb2c1a0946349c0d04f7ef8f0d315b652160a65 should've fixed this problem

any chance you are using it on Divio Cloud? if that's the case and the addon was upgraded - please make sure that the static files and template are removed from the project.

i will try to reproduce in the meantime

SteinRobert commented 5 years ago

I'm using version 1.0.0. Let me know if you cannot reproduce the issue. I'll have a look at removing the templates and statics. It is indeed a customized docker image we're using.

Edit: I deleted the statics and templates - this did not change the behavior. Selecting an icon from the 2nd iconset leaves the user with a preselection of the first icon of the first iconset when opening the admin/plugin again...

Edit2: @vxsx I noticed this behavior only with 2 SVG sprites so the first step of the reproduction is wrong. The setting should look like this:

DJANGOCMS_ICON_SETS = [
    (ICONSET, 'icon', 'SVG icons'),
    (ICONSET2, 'icon2', 'SVG icons 2'),
]
vxsx commented 5 years ago

I can reproduce the problem with 2 svg iconsets, thanks, looking into this

vxsx commented 5 years ago

It looks like the field renderer tries to infer the iconset out of the icon name:

https://github.com/divio/djangocms-icon/blob/dd8abebd32ffb94e001dd3028e8f01b5fd84cb8d/djangocms_icon/fields.py#L31-L37

Meaning that if value is icon-something it would think that the prefix is icon. So it would select the iconset based on that. And in case the iconset prefix doesn't match the one in settings it would always pick the first one no matter what. This is likely what leads to the bug you're experiencing

SteinRobert commented 5 years ago

I can confirm this. Changing the prefix in my second symbol-def SVG file make the whole thing work.