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

get-data/set-data! don't seem to work with "normal" data attributes #60

Open
ddellacosta opened this issue Jul 18, 2013 · 5 comments
Open

Comments

@ddellacosta
Copy link

I'm not really sure how to structure this issue, but basically I'm curious about the thinking behind get-data and set-data!. It seems that, rather than returning/modifying data attributes, they modify a custom "__domina_data" attribute. If one expects to be able to do something like retrieve or add/update an HTML data attribute, they don't work.

Can you give a use-case for get-data/set-data! ?

@ddellacosta
Copy link
Author

I should add, it's easy enough just to use attr/set-attr! with data- attributes, so no big deal. Just curious what the thinking is behind these functions.

@ckirkendall
Copy link
Collaborator

set-data and get-data are borrowed directly from JQuery's data() method(http://api.jquery.com/data/). The idea behind it is to attache arbitrary keyed data to dom node. This is often used to temporary store additional information that later events on the node will use.

@ddellacosta
Copy link
Author

Thanks for the explanation!

Certainly this is in how jQuery's data functions work in general. However, jQuery's data "getter" functions explicitly access the data attributes set on HTML elements, as described in this section from the link you provided above:

http://api.jquery.com/data/#data-html5

domina obviously does not do this (https://github.com/levand/domina/blob/master/src/cljs/domina.cljs#L399). Again, it's a minor inconvenience, as it easy enough to acquire and set data attributes using attr/set-attr!, if need be. However, it may make sense to do either one of two things: add support for getting the HTML data attributes initially as jQuery does, or add some documentation to explicitly note that get-data attributes are unrelated to HTML data attributes, and they will be ignored.

I would advocate for the former, as I suspect it is what most users would expect, especially those familiar with jQuery--I was certainly surprised by this behavior initially.

In any case, I'd be happy to do either and submit a pull request, but I wanted to understand how the domina team felt about this before doing so.

@ckirkendall
Copy link
Collaborator

@ddellacosta I was unaware of the attribute reads in the JQuery get data. I don't know about Luke but I don't see any issues with supporting it. Basically we would have to read the data in from the attributes the first time get-data! or set-data! was accessed. @levand you have a take on this? The implementation seems fairly straight forward.

@Gonzih
Copy link

Gonzih commented Oct 13, 2014

Hi guys, are there any update on proper support for html5 data attributes?

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

3 participants