Skip to content

make separator configurable#17

Closed
pirxpilot wants to merge 1 commit intodevelopit:masterfrom
pirxpilot:separator-config
Closed

make separator configurable#17
pirxpilot wants to merge 1 commit intodevelopit:masterfrom
pirxpilot:separator-config

Conversation

@pirxpilot
Copy link
Contributor

it's still comma by default but you can pass { separator: ' ' } or { separator: ':' } as an option argument when creating tags-input

@developit
Copy link
Owner

Thought: what about having it be an attribute on the input?

<input type="tags" data-separator=":" value="foo:bar:baz">

@pirxpilot
Copy link
Contributor Author

Yup. Much better. Let me rework it.

`data-separator` attribute on a wrapped input element can be used to
specify tags separator

We use `KeyboardEvent.key` to detect separator, if browser does not
support it (Safari) we fall back to KeyboardEvent.keyIdentifier

see:
http://caniuse.com/#search=KeyboardEvent.key
@pirxpilot
Copy link
Contributor Author

Some fixes:

  • implemented data-separator
  • fixed char detection - Safari does not actually support neither key nor char on keydown events - we need to parse keyIdentifier to properly detect separator char

@luckydonald
Copy link

How can one specify multible seperators? E.g. "," and enter?

base.input.addEventListener('keydown', e => {
let el = base.input,
key = e.keyCode || e.which,
char = charFromKeyboardEvent(e),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm - I think we could just use String.fromCharCode(key) here, couldn't we?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish. If only Safari behaved ;-)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but its using keyCode, not charCode. I thought that worked? 😥

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - keyCode works in most browsers on keypress event. But on keydown a different story.
Mobile (iOS) Safari tends to have strange values in keyCode on keydown - for example , (comma) generates 188 which corresponds to '¼'. I am sure that there is some logic behind it, and I am sure that we are up for yet another how to translate key events to key value standard at some point, but for now we are still in the waving hands and magic land.

@developit
Copy link
Owner

@luckydonald by pasting

@pirxpilot
Copy link
Contributor Author

pirxpilot commented Dec 15, 2016

@luckydonald - enter and tab is always a separator, as for others you can specify a string with multiple charactes - see: https://pirxpilot.github.io/tags-input/
Source for the demo is here: https://github.com/code42day/tags-input/blob/next/index.html

@developit
Copy link
Owner

Ah now I see what was being asked haha.
Nice demo @pirxpilot

@pirxpilot
Copy link
Contributor Author

Detecting keys is tricky, not all documented properties are set on all events. For example charCode is not set in most browsers on keyDown.
see: https://dvcs.w3.org/hg/d4e/raw-file/tip/key-event-test.html

@0xc00010ff
Copy link

🙏

@tumpio
Copy link

tumpio commented Jun 5, 2017

@pirxpilot pirxpilot closed this Feb 22, 2024
@pirxpilot pirxpilot deleted the separator-config branch February 22, 2024 06:36
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

Successfully merging this pull request may close these issues.

5 participants