Skip to content
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ a little description and the default value:
| **tags-input-name** | `String` | `"tag"` | Name to use as `name=""` in single tags' input. By default, all tags being passed as array like `tag[]`. |
| **tags-limit** | `Integer` | `0` | Limit the number of tags that can be added, zero for no limit. |
| **type-zone-class** | `String` | `"type-zone"` | Class of the type-zone. |
| **allowed-words** | `Array` | `[]` | Array of allowed words. |
| **allowed-words-callback** | `Function` | `window.alert` | Function to call when allowed words are not detected. |
| **allowed-words-text** | `String` | `"Tag not allowed:"` | Basic text passed to when allowed words not detected `allowed-words-callback`. |

## Available Methods ##

Expand Down
29 changes: 27 additions & 2 deletions tagging.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@
"tags-input-name": "tag", // Name to use as name="" in single tags (by default tag[])
"tag-on-blur": true, // Add the current tag if user clicks away from type-zone
"tags-limit": 0, // Limit the number of tags that can be added, zero means no limit
"type-zone-class": "type-zone" // Class of the type-zone
"type-zone-class": "type-zone", // Class of the type-zone
"allowed-words": [], // Array of allowed words
"allowed-words-callback": window.alert, // Function to call when there is a allowed words
"allowed-words-text": "Tag not allowed:" // Basic text passed to allowed-words callback

},

/**
Expand All @@ -99,7 +103,7 @@

var $tag, l, self,
index, forbidden_words,
callback_f, callback_t;
callback_f, callback_t, allowed_words;

// Caching this
self = this;
Expand All @@ -115,6 +119,8 @@
// Forbidden Words shortcut
forbidden_words = self.config[ "forbidden-words" ];

allowed_words = self.config[ "allowed-words"];

// If no text is passed, take it as text of $type_zone and then empty it
if ( ! text ) {
text = self.valInput();
Expand Down Expand Up @@ -153,6 +159,25 @@
}
}

// Check if text is allowed or not
l = allowed_words.length;
while ( l-- ) {

// looking for words which are allowed
if ( ! allowed_words.includes(text) ) {

// Removing all text and ','
self.emptyInput();

// Renaiming
callback_f = self.config[ "allowed-words-callback" ];
callback_t = self.config[ "allowed-words-text" ];

// Remove as a duplicate
return self.throwError( callback_f, callback_t, text );
}
}

// If no-duplicate is true, check that the text is not already present
if ( self.config[ "no-duplicate" ] ) {

Expand Down
2 changes: 1 addition & 1 deletion tagging.min.js

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