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

@morsedigital/select-filter

v1.0.1

Published

Allows a select to call api to filter results in another select.L0

Downloads

20

Readme

select-filter

Allows a select to call api to filter results in another select.L0

Install into project

yarn add @morsedigital/select-filter

Set up your HTML like so:

<select data-select-filter="second-select" data-select-filter-api="my/api/path" id="first-select">
  <option value="1">Option 1</option>
  <option value="2">Option 2</option>
</select>

<select id="second-select"> </select>

'data-select-filter' is id of the select you want updated

'data-select-filter-api' is the api path to where you are going to pull the data from.

In javascript add the following way:

import SelectFilter from "@morsedigital/select-filter";

(() => {
  SelectFilter();
})();

Then when the select is changes it will hit the api + value. So in this example if 'Option 1' is selected the a request is sent to 'my/api/path/1'.

The response should be as json like so:

[
  {
    "title": "Option",
    "value": "some value"
  },
  {
    "title": "Another Option",
    "value": "another value"
  }
]

and the select will be updated like so:

<select id="second-select">
  <option value="some value">Option</option>
  <option value="another value">Another Option</option>
</select>

You can also change the way the api is called.

If you prefer a query string:

import SelectFilter from "@morsedigital/select-filter";

(() => {
  SelectFilter({ query: true });
})();

Then when the select is changes it would call 'my/api/path?value=1'.

Or if you would prefer to POST the data for the following:

import SelectFilter from "@morsedigital/select-filter";

(() => {
  SelectFilter(
    { query: false },
    {
      method: "POST"
      //... other fetch options
      // see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
    }
  );
})();

Then when the select is changes it would call 'my/api/path' with a json body of { value: 1 }

Bug reports

If you discover any bugs, feel free to create an issue on GitHub. Please add as much information as possible to help us fixing the possible bug. We also encourage you to help even more by forking and sending us a pull request.

https://github.com/morsedigital/select-filter/issues

Contribute

If you'd like to contribute, @morsedigital/select-filter is written using babel and rollup in ES6.

Please make sure any additional code should be covered in tests (Jest).

If you need to run the test please use:


yarn test

or to rebuild the JS run:


yarn build

Maintainers

Adrian Stainforth (https://github.com/djforth)

License

@morsedigital/select-filter is an open source project falling under the MIT License. By using, distributing, or contributing to this project, you accept and agree that all code within the @morsedigital/select-filter project are licensed under MIT license.