Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot be able to retrieve data attribute when selectize is rendering #2086

Open
FranRomero opened this issue Feb 21, 2024 · 0 comments
Open

Comments

@FranRomero
Copy link

I am maintaining a project that is using selectize for its dropdowns. What I am trying to do is to retrieve data from data-* attributes so I can use that data when rendering, specifically, I want to pass through data attribute an image url so I can associate each option to its corresponding image.

According to docs, there is a dataAttr Selectize option, which default value is 'data-data' so I tried to include that attribute on HTML.

<option value="demovalue" data-data="{literal}{'demo': 'demo'}{/literal}">text</option>. I am using {literal} tags as I am using Smarty.

And I am trying to retrieve data like this:

$(this).selectize({
      plugins: selectizePlugins,
      hideSelected: true,
      copyClassesToDropdown: false,
      closeAfterSelect: true,
      allowEmptyOption: true,
      render: {
          option: function (data, escape) {
              console.log(data);
              return "<div data-url-image='" + escape(data.data) + "'>" + escape(data.text) + "</div>"
          }
      }
  });

I also tried adding dataAttr: 'data-data' to selectize options, but with the same result.

I am unable to get this data attribute on Javascript code. I saw a lot of examples on the internet even here on old tickets but I cannot it work.

Is it a bug?

NOTE: I am using v0.13.5 of Selectize and Smarty as PHP framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant