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 3 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
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
4 changes: 4 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: 'Custom Placeholder',
muratgorken marked this conversation as resolved.
Show resolved Hide resolved
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) {
return this.placeHolderText;
}
const usePlural = totalItems !== 1 && this.textPlural.length > 0;
const text = usePlural ? this.textPlural : this.selectionText;
return `${totalItems} ${text}`;
Expand Down