Giter Club home page Giter Club logo

Comments (11)

paulstraw avatar paulstraw commented on August 18, 2024

This isn't documented at the moment, but you can pass classes along using a data-class attribute. I'm considering what to do about other data-* attributes, but haven't landed on a solution quite yet. Can you describe your use case for needing to send these along? It might help me figure out a good solution.

from fancyselect.

pkhodaveissi avatar pkhodaveissi commented on August 18, 2024

I was gonna pass those data-* attributes so I can check on the selected option and the value of this attribute and change some part of the page I'm working with...

from fancyselect.

paulstraw avatar paulstraw commented on August 18, 2024

You don't need to use data attributes to check the selected option. Just check it on the select itself as per usual:

$('#my-select').val();

from fancyselect.

pkhodaveissi avatar pkhodaveissi commented on August 18, 2024

not the value of option itself, I use that somewhere else, I needed data-* attrs specially to specify something else than the value of option itself, you can imagine the value of an option is "iPod" and the value of data-category is "Music Player" or something like that...

thanks for the fast response

from fancyselect.

paulstraw avatar paulstraw commented on August 18, 2024

Ah, I see. Now that I'm thinking about it, there's probably no need to pass along data attributes other than data-class anyhow, since you can just access them directly on the select:

var mySelect = $('#my-select');

mySelect.fancySelect();

var someData = mySelect.data('whatever');

Any reason that wouldn't work for your use case?

from fancyselect.

pkhodaveissi avatar pkhodaveissi commented on August 18, 2024

what does this going to return?
var someData = mySelect.data('whatever');
I'm asking this since the list item generated by fancySelect doesn't have the exact attributes that each option itself has

from fancyselect.

paulstraw avatar paulstraw commented on August 18, 2024

If:

<select id="mySelect" data-whatever="something">
    <option>Foo</option>
</select>

Then:

var mySelect = $('#my-select');

mySelect.fancySelect();

var someData = mySelect.data('whatever');
// someData == 'something'

Exactly like using jQuery's data normally.

from fancyselect.

pkhodaveissi avatar pkhodaveissi commented on August 18, 2024

you see It was my mistake if I didn't describe my problem right,

the problem is that I assign some kinda data-* attrs to 'option' elements not the 'select' element itself, just like the example: option is 'iPod' and data-cat of that specific option is 'Music Player'...
your solution returns the data attribute of select element, please tell me where I'm mistaken...

from fancyselect.

paulstraw avatar paulstraw commented on August 18, 2024

Oh, I see. I guess I misunderstood.

You could do something like this:

$('#my-select').on('change', function() {
    var el = $(this),
        cat = el.find('option:selected').data('cat')
});

Again, pretty similar to what you'd to do with a normal select.

EDIT: Updated with cleaner code. Also, working code.

from fancyselect.

pkhodaveissi avatar pkhodaveissi commented on August 18, 2024

I see, I can mange something with that,

thanks, for the time and effort

from fancyselect.

paulstraw avatar paulstraw commented on August 18, 2024

I'm going to leave this open for a bit to remind me to update the docs. Glad I could help.

from fancyselect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.