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

Comma detection broken on foreign keyboards #22

Open
ishirav opened this issue Aug 23, 2011 · 7 comments
Open

Comma detection broken on foreign keyboards #22

ishirav opened this issue Aug 23, 2011 · 7 comments

Comments

@ishirav
Copy link

ishirav commented Aug 23, 2011

Hi,

The way tag-it detects a comma keypress does not work on some keyboard layouts. For example, in the Hebrew keyboard layout the comma is on a different key, and where the comma usually is - there's the letter Tav. So when you use tag-it with such a keyboard, each time you try to input a word with Tav in it, the tag is closed instead.

I've implemented a very simple fix, which uses event.charCode to detect the comma instead of relying on $.ui.keyCode.COMMA
Handling the comma then has to be moved to the keypress event instead of keydown, because event.charCode is not available on keydown. See below:

            // Events.
            this._tagInput
                .keydown(function(event) {
                    // Backspace is not detected within a keypress, so it must use keydown.
                    if (event.which == $.ui.keyCode.BACKSPACE && that._tagInput.val() === '') {
                        var tag = that._lastTag();
                        if (!that.options.removeConfirmation || tag.hasClass('remove')) {
                            // When backspace is pressed, the last tag is deleted.
                            that.removeTag(tag);
                        } else if (that.options.removeConfirmation) {
                            tag.addClass('remove ui-state-highlight');
                        }
                    } else if (that.options.removeConfirmation) {
                        that._lastTag().removeClass('remove ui-state-highlight');
                    }

                    // Space/Enter are valid delimiters for new tags,
                    // except when there is an open quote or if setting allowSpaces = true.
                    // Tab will also create a tag, unless the tag input is empty, in which case it isn't caught.
                    if (
                        event.which == $.ui.keyCode.ENTER ||
                        (
                            event.which == $.ui.keyCode.TAB &&
                            that._tagInput.val() !== ''
                        ) ||
                        (
                            event.which == $.ui.keyCode.SPACE &&
                            that.options.allowSpaces !== true &&
                            (
                                $.trim(that._tagInput.val()).replace( /^s*/, '' ).charAt(0) != '"' ||
                                (
                                    $.trim(that._tagInput.val()).charAt(0) == '"' &&
                                    $.trim(that._tagInput.val()).charAt($.trim(that._tagInput.val()).length - 1) == '"' &&
                                    $.trim(that._tagInput.val()).length - 1 !== 0
                                )
                            )
                        )
                    ) {
                        event.preventDefault();
                        that.createTag(that._cleanedInput());

                        // The autocomplete doesn't close automatically when TAB is pressed.
                        // So let's ensure that it closes.
                        that._tagInput.autocomplete('close');
                    }
                }).keypress(function(event){
                    // Comma character (has to be checked on keypress, because charCode is 0 in keydown event)
                    if (event.charCode == 44) {
                        event.preventDefault();
                        that.createTag(that._cleanedInput());
                    }
                }).blur(function(e){
                    // Create a tag when the element loses focus (unless it's empty).
                    that.createTag(that._cleanedInput());
                });
@weekens
Copy link

weekens commented May 6, 2012

Same problem with Russian "б". I need to try your fix.

@CrazyClicker
Copy link

Thx, ishirav, had the same probles. U saved my time!

@PanJ
Copy link

PanJ commented Jun 14, 2012

I think this fix should be applied in the next release. Facing the same problem too.

@zmichael
Copy link

zmichael commented Nov 7, 2013

Thank you very much!
works awesome !
russian б types like a charm :)

@artyil
Copy link

artyil commented Dec 30, 2013

Thanks !

@oak-tree
Copy link

thanks works. after two years and i agree with @PanJ this should get into next release

rozzy added a commit to jeenio-backup/tag-it that referenced this issue Nov 24, 2015
@yogeshmatta
Copy link

Hi,
I have an issue that in android device when I press space key it does not make tag. but it works fine desktop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants