Using 'enter'-key to add new items

Dofs's Avatar

Dofs

06 May, 2011 08:57 AM

Hi,

I would like to be able to add tags by using the enter key (not only tab or comma). I have tried to add the tab-funktionality to the enter event, and just do a check on there any active, but this doesn't work properly.

Has anyone tried to hack the plugin to add the funktionality of the tab event to the enter key?

(around line 198)

                        case 13: // return
                        tab_press = false;
                        var active = $("li.active:first", results_holder);
                        if (active.length < 1) {
                            tab_press = true;
                            var i_input = input.val().replace(/(,)/g, "");
                            if (i_input != "" && values_input.val().search("," + i_input + ",") < 0 && i_input.length >= opts.minChars) {
                                e.preventDefault();
                                var n_data = {};
                                n_data[opts.selectedItemProp] = i_input;
                                n_data[opts.selectedValuesProp] = i_input;
                                var lis = $("li", selections_holder).length;
                                add_selected_item(n_data, "00" + (lis + 1));
                                input.val("");
                            }
                        } else {
                            if (active.length > 0) {
                                active.click();
                                results_holder.hide();
                            }
                            if (opts.neverSubmit || active.length > 0) {
                                e.preventDefault();
                            }
                        }
                          break;

Best Regards
Dofs

  1. 1 Posted by Dofs on 06 May, 2011 11:08 AM

    Dofs's Avatar

    I found the answer, I replaced "If(active.length > 1) with the following code:

       if ($(".active", results_holder).length == 0 || jQuery(active).text() == opts.emptyText) {
    
  2. 2 Posted by Greg on 21 Jun, 2011 02:24 PM

    Greg's Avatar

    Just a correction -

    "I found the answer, I replaced "If(active.length < 1) with the following code:"

    So it is less than 1, not greater..

    Thanks for the solution!

    G

  3. 3 Posted by Tridem on 02 Jul, 2012 11:03 AM

    Tridem's Avatar

    Nice feature working fine, thanks!

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