npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

checklist-model

v1.0.0

Published

AngularJS directive for list of checkboxes

Downloads

82,738

Readme

Bower NPM License

NPM

checklist-model

AngularJS directive for list of checkboxes

Why this is needed?

In Angular one checkbox <input type="checkbox" ng-model="..."> is linked with one model.
But in practice we usually want one model to store array of checked values from several checkboxes.
Checklist-model solves that task without additional code in controller.

Live demo

http://vitalets.github.io/checklist-model

Installation

Note: since version 1.0.0 you must install the angular library yourself as it is now a peerDependency

  1. Download package:
    • From npm npm install checklist-model
    • From bower bower install checklist-model
    • From latest release
  2. Include script to the HTML:
    <script src='checklist-model.js'></script>
  3. Add to app dependencies:
    var app = angular.module("app", ["checklist-model"]);

Usage

You should play with attributes of <input> tag:

| Attribute | Mandatory | Description | | :-----------------------: | :-------: | --------------------------------------------- | | checklist-model | Yes | Use instead of ng-model | | checklist-value | No | What should be picked as array item | | value | No | What should be picked as item, but unlike checklist-value, this does not evaluate as an angular expression, but rather a static value | | ng-model | No | Every checkbok will span a new scope and define a variable named checked to hold its state. You can modify this name by using this attribute. | | checklist-comparator | No | A custom comparator. If it starts with dot(.) then it will be an expression applied to the array item. Otherwise it should evaluate to a function as an angular expression. The function return true if the first two arguments are equal and false otherwise. | | checklist-before-change | No | An angular expression evaluated each time before the checklist-model has changed. If it evaluates to 'false' then the model will not change anymore. | | checklist-change | No | An angular expression evaluated each time the checklist-model has changed. |

  • If you modify directly the value of the checklist-model, it is possible that the UI won't be updated. This is because this directive looks for the model in the parent, not in the current scope. Instead of doing checklistModelList = [] you should do checklistModelList.splice(0, checklistModelList.length) or wrap it in another object. Consequently, instead of doing checklistModelList = angular.copy(allValues) you should do checklistModelList.push.apply(checklistModelList, allValues). The idea is to use the same array and not replace it with a new one.
  • If you're using track by you must specify the same thing for checklist-value too. See #46.
  • If you're also using ngModel, please keep in mind that the state of the checkbok is initialized with the value from checklistModel, not with the one from ngModel. Afterwards the two will be kept in sync, but initially, these two can be conflicting, so only checklistModel is used. See the entire discussion at #104.

Examples

  • JsFiddle basic example (use this to report any issue): http://jsfiddle.net/beradrian/fjoLy5sq/
  • JSFiddle required example: http://jsfiddle.net/beradrian/7wt9q1ev/
  • Plunkr example: http://plnkr.co/edit/0UrMwtiNQxJJbVWnYgSt?p=preview
  • Plunkr example for tree list

How to get support

Please keep in mind to also add a Plunkr or JSFiddle example. This will greatly help us in assisting you and you can use one of the existing examples and fork it.

Development

How to run tests

  1. Generate live demo index.html via grunt jade
  2. Run local http server grunt server
  3. Open in browser http://localhost:8000 to check that demo is accessible
  4. Open in browser http://localhost:8000/test and wait until all tests pass

How to add a new test case

  1. Create a new folder under docs/blocks named your-test.
  2. Create under that folder ctrl.js to describe the test Angular controller, view.html to describe the view part in HTML and test.js for the Angular scenario test. You can use an existing test as an example.
  3. Add a line like - items.push({id: 'your-test', text: 'Your test, ctrlName: 'CtrlTestName', testValue: 'selectedItems'}) to docs/index.jade
  4. Add a line like <script src="../docs/blocks/your-test/test.js"></script> to test\index.html
  5. Run grunt jade to generate index.html from docs/index.jade
  6. Run grunt server
  7. Access http://localhost:8000 for samples and http://localhost:8000/test for running the tests.

How to make a new release

  1. Change the version number in package.json, bower.json and checklist-model.nuspec (if not already changed - check the version number against the latest release in Github)
  2. Create a new release in github with the same name for tag and title as the version number (e.g. 1.0.0). Do not forget to include the changelog in the release description.
  3. Run npm publish to publish the new version to npm

License

MIT