list.js
list.js copied to clipboard
Value getters
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:
- the element with that class, which may be
undefined
(so you can return a default) or you can do something with that element. - the index in the list (if that's important for some reason)
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!
@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/
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.