Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added custom placeholder option. #46

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ $(document).ready(() => {
#### Dropdown options using data attributes

```html
<div class="iqdropdown">
<div class="iqdropdown" data-placeholder="Custom Placeholder">
<p class="iqdropdown-selection" data-seletion-text="item" data-text-plural="items"></p>
<div class="iqdropdown-menu">
...
Expand Down Expand Up @@ -116,6 +116,8 @@ $(document).ready(() => {
selectionText: 'item',
// text to show for multiple items
textPlural: 'items',
// text to show placeholder
placeHolderText: 'Custom Placeholder',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think placeholder is a better name so it matches the data-prop attribute

// optionally can use setSelectionText function to override selectionText
setSelectionText: (itemCount, totalItems) => { /* return string */ },
// buttons to increment/decrement
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'styles/main.scss';
minItems: 0,
selectionText: 'item',
textPlural: 'items',
placeHolderText: '',
controls: {
position: 'right',
displayCls: 'iqdropdown-content',
Expand All @@ -21,6 +22,9 @@ import 'styles/main.scss';
beforeDecrement: () => true,
beforeIncrement: () => true,
setSelectionText (itemCount, totalItems) {
if (totalItems == 0 && this.placeHolderText != '') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

equality and inequality should use === and !== accordingly

return this.placeHolderText;
}
const usePlural = totalItems !== 1 && this.textPlural.length > 0;
const text = usePlural ? this.textPlural : this.selectionText;
return `${totalItems} ${text}`;
Expand All @@ -36,6 +40,7 @@ import 'styles/main.scss';
const dataAttrOptions = {
selectionText: $selection.data('selection-text'),
textPlural: $selection.data('text-plural'),
placeHolderText: $this.data("placeholder"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strings must use single quotes. you can check for lint errors running yarn lint

};
const settings = $.extend(true, {}, defaults, dataAttrOptions, options);
const itemCount = {};
Expand Down