How to make free text entries comply with selectionLimit

Paolo's Avatar

Paolo

09 Aug, 2011 01:11 PM

Let's say you have your selectionLimit set to 5. Then once you have selected five items and try to add more, you get the message "No more selections are allowed". So far so good. However, that does not stop you from manually entering free text entries separated by a comma, which means you can still add unlimited free text entries.

Well, if you would like the selectionLimit to apply to all entries, including free text, then this is what you do:

First:
Change line 193 in jquery.autoSuggest.js from:
add_selected_item(n_data, "00"+(lis+1));

to:
if ((opts.selectionLimit && $("li.as-selection-item", selections_holder).length < opts.selectionLimit){ add_selected_item(n_data, "00"+(lis+1)); }

That's it. It will now disallow free text entries once the selectionLimit has been reached.

NOTE!!!!

For those of you that used the code that Xnuiem added for the no Free Text option in this discussion (https://drew.tenderapp.com/discussions/autosuggest/129-tab-and-comm...), the line now changes to this:

if (false == opts.noFree && (opts.selectionLimit && $("li.as-selection-item", selections_holder).length < opts.selectionLimit)){ add_selected_item(n_data, "00"+(lis+1)); }

Cheers

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac