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

angular-checkboxes

v1.0.3

Published

Bind a list of checkboxes to a unique ng-model array

Downloads

54

Readme

angular-checkboxes

Bind a list of checkboxes to a unique ng-model array.

npm version Build Status Code Climate Test Coverage

dependency Status devDependency Status

What is it?

If you are used to manipulate HTML forms, you probably know that each checkbox is a separate variable (or maybe an ngModel with AngularJS).

Sometimes, it could be usefull to manipulate all these checkboxes as a unique array.

angular.checkboxes module lets you turn your list of checkboxes into a unique destination array, providing :

  • two-way binding: manipulate the destination array will check/uncheck the checkboxes AND check/uncheck the checkboxes will modify the destination array.
  • no isolated scope for each checkbox: the directive does not create new child scope.
  • a mtCheckboxController: internal controller can be injected to other directives.

Demos & usage

http://msieurtoph.github.io/angular-checkboxes

Installation

npm i angular-checkboxes --save

Simple Example

Please, visit http://msieurtoph.github.io/angular-checkboxes for live examples.

<form>
    ...
    <div mt-to="myUniqueArray">
        <input type="checkbox" mt-checkbox name="value1" /> Value 1 <br/>
        <input type="checkbox" mt-checkbox name="value2" /> Value 2 <br/>
        <input type="checkbox" mt-checkbox name="value3" /> Value 3 <br/>
    </div>
    ...
</form>

Let's check Value 1 and Value 2, and you will get (in the current scope):

myUniqueArray= [
    "value1",
    "value2"
];

Let's push value3 to myUniqueArray now, and you will check the Value 3 checkbox.

Pretty cool, no ?

/!\ Do not forget to $apply() the scope changes when manipulating destination array!

What if the checkbox also has an ngModel

Don't care about that, the module takes it in charge. Just use them if you need, they will be updated with the flow: if you add or remove a value from the destination array, the checkbox ngModel (a boolean) will be switched.

The only thing to know is : during the initialisation phase, if the ngModel state of the checkbox differs from its state in the destination array, the ngModel will be overriden. So if the checkbox is checked, but the value is not in the array : the checkbox will be unchecked...

A possible enhancement could be to add an option (in the Provider or as an attribute) to force it to work the other way and give the checkbox ngModel the priority on the array.

mtCheckboxController

The directive mtCheckbox provides a controller. It publishes :

  • value (string)

    The value that will be pushed to/shifted from the destination array for this checkbox. See the demo page to know how to initialize it.

  • state (boolean)

    It tells if the checkbox is currently checked or not. It is better not to change this state manually and prefer the set(state) method.

  • set(state) (function(boolean))

    It allows external directives to check (value=true) or uncheck (value=false) the checkbox programmatically. Any other non-boolean value will do nothing.

mtToController

The directive mtTo provides a controller too. It publishes :

  • get() (function())

    The getter for the destination array.

  • set(list) (function(array))

    The setter for the destination array. The provided array will replace the existing one.

  • indexOf(elt) (function(elt))

    To get the index of the provided element in the destination array.

  • add(elt) (function(elt))

    To push an element to the destination array, except if the element is already added.

  • remove(elt) (function(elt))

    To remove an element from the destination array, if present.