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

Value getters #630

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Value getters #630

wants to merge 1 commit into from

Conversation

benhowes
Copy link

@benhowes benhowes commented Dec 5, 2018

Background: I have a usecase where it's really handy for me to be able to filter and sort on if a checkbox is checked. For some reason the ~/utils/getAttribute.js implementation does not work on the checked attribute. elm.checked does work however, as does elm.hasAttribute("checked"). I figured all kinds of weird and wacky use-cases have probably come up over the years that you've had this project. So I want to propose a way that I can hook my own value getter for a list element.

This still get's the list item by class, e.g. for me I have list items which look like this:

<li class="group">
  <input type="checkbox" value="checked" class="toggle-state" />
  <h3 class="name">...</h3>
</li>

This PR allows me to do the following:

var options = {
  valueNames:[
    "name",
    {name: "toggle-state", getter: function(elm, index){ return elm ? elm.checked : false }}
}
var list = new List('project-list', options);

the getter function takes the following as its arguments:

  1. the element with that class, which may be undefined (so you can return a default) or you can do something with that element.
  2. the index in the list (if that's important for some reason)

@thewasta
Copy link

Hello there! Can anyone please explain this? I'm newbie in git/github. What does this means
This branch has no conflicts with the base branch ? Is this a update for the code? Because in the documentation there is not information about getter in the object of valueNames, just attr.
I'm very confused....
Thanks!

@benhowes
Copy link
Author

@thewasta this is a "suggestion" for a change to the code, but is not part of the main codebase yet (i.e. this is a branch which has not been merged with the main branch).

If I may, I kindly suggest that you read up on git and github online because there is a lot to explain in order to answer your question. There are some great resources here: https://guides.github.com/

@javve
Copy link
Owner

javve commented Nov 21, 2020

Sorry about the super late reply. This sounds interesting. I'll investigate some myself and see how we can make sure checkboxes work.

A getter sounds pretty fancy/advanced, but if I can't come up with a more general solution that may be the best way.

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

Successfully merging this pull request may close these issues.

None yet

3 participants