Skip to content

Commit

Permalink
Add function to provide custom message (#11) (#12)
Browse files Browse the repository at this point in the history
* Add function to provide custom message

* Declare setSelectionText function in defaults object

* Show selection text from data-attribute

* Update documentation

* rebuild
  • Loading branch information
rtgreen86 authored Feb 19, 2020
1 parent a074da4 commit c60e536
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 8 deletions.
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ $(document).ready(() => {

### Config options

#### Dropdown options using data attributes

```html
<div class="iqdropdown">
<p class="iqdropdown-selection" data-seletion-text="item" data-text-plural="items"></p>
<div class="iqdropdown-menu">
...
</div>
</div>
```

#### Item specific using data attributes

```html
Expand All @@ -101,10 +112,12 @@ $(document).ready(() => {
maxItems: Infinity,
// min total items
minItems: 0,
// text to show on the dropdown
// text to show on the dropdown override data-selection-text attribute
selectionText: 'item',
// text to show for multiple items
textPlural: 'items',
// optionally can use setSelectionText function to override selectionText
setSelectionText: (itemCount, totalItems) => { /* return string */ },
// buttons to increment/decrement
controls: {
position: 'right',
Expand All @@ -121,6 +134,41 @@ $(document).ready(() => {
}
```

#### Selection text

Default value.

```javascript
`${totalItems} item` // if total items is 1
`${totalItems} items` // if total items is not 1
```

Data attribute `data-selection-text` override default value.

```html
<p class="iqdropdown-selection" data-seletion-text="item" data-text-plural="items">
```

Property `selectionText` override data attribute

```javascript
options.selectionText = 'item';
options.textPlural = 'items';
```

Function `setSelectionText` override `selectionText` property.

```javascript
options.setSelectionText = function setSelectionText(itemCount, totalItems)
```

Arguments:

- *itemCount* <object> - keys - items data-id; values - items count
- *totalCount* <number> - total items count

Return selection text <string>.

### Demo

A demo is included [here](https://github.com/reserbus/item-quantity-dropdown/blob/master/lib/index.html)
Expand Down
2 changes: 1 addition & 1 deletion lib/item-quantity-dropdown.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c60e536

Please sign in to comment.