https://github.com/rusty1s/dependent-select-boxes
Allows a child select box to change its options dependent on its parent select box
https://github.com/rusty1s/dependent-select-boxes
Last synced: over 1 year ago
JSON representation
Allows a child select box to change its options dependent on its parent select box
- Host: GitHub
- URL: https://github.com/rusty1s/dependent-select-boxes
- Owner: rusty1s
- License: mit
- Created: 2016-04-06T12:01:43.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-08-18T07:18:53.000Z (almost 9 years ago)
- Last Synced: 2025-03-10T10:04:36.892Z (over 1 year ago)
- Language: JavaScript
- Homepage: http://rusty1s.github.io/dependent-select-boxes/demo
- Size: 19.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dependent-select-boxes
`dependent-select-boxes` allows a child select box to change its options dependent on its parent select box.
[Demo](http://rusty1s.github.io/dependent-select-boxes/demo)
## Additional options
You can pass in options as a third parameter. The currently supported options are:
* `childOptionIsDependentOnParentOption(childOption, parentOption)`:
Function that determines if the `childOption`should be displayed if
`parentOption` is selected. Default: `true` if the value of the parent
option is a prefix of the value of the child option, else `false`.
* `resetParentOptionOnEmptyChildOption`:
Resets the parent option to an empty value if the child option changes
to an empty option. Default `true`.
```js
new DependentSelectBoxes(document.getElementById('parent'), document.getElementById('child'), {
childOptionIsDependentOnParentOption(childOption, parentOption) {
...
},
resetParentOptionOnEmptyChildOption: false,
});
```
You can configure the default options by setting them via:
```js
import { setDefaultOptions } from 'dependent-select-boxes';
setDefaultOptions({
...
});
```
## Node
```js
// npm install dependent-select-boxes --save
import DependentSelectBoxes from 'dependent-select-boxes';
const dependentSelectBoxes = new DependentSelectBoxes(parent, child, options);
```
## Contributing
If you would like to [submit a pull request](https://github.com/rusty1s/dependent-select-boxes/pulls)
with any changes you make, please feel free!
Simply run `npm test` to test and `npm start` to compile before submitting pull requests.
## Issues
Please use the [GitHub issue tracker](https://github.com/rusty1s/dependent-select-boxes/issues)
to raise any problems or feature requests.