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

Ensure tags must fit pattern before adding them #21

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

mikemaccana
Copy link
Contributor

Fixes #20

@developit developit self-requested a review April 10, 2017 13:44
@thomasdegry
Copy link

@developit any reason why we can't merge this yet? Would be awesome to have this functionality working!

@developit
Copy link
Owner

Array.prototype.includes() is not supported in IE9, which this library targets.

@@ -45,15 +45,26 @@ export default function tagsInput(input) {
// Return false if no need to add a tag
function addTag(text) {
// Add multiple tags if the user pastes in data with SEPERATOR already in it
if (~text.indexOf(SEPERATOR)) text = text.split(SEPERATOR);
if (Array.isArray(text)) return text.forEach(addTag);
if ( text.includes(SEPERATOR) ) {
Copy link
Owner

Choose a reason for hiding this comment

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

seems a shame to give up IE compat here

@mikemaccana
Copy link
Contributor Author

We could just add a polyfill for legacy browsers. This keeps the code clean and can be deleted quickly when you finally drop IE. :^)

@developit
Copy link
Owner

I'm too obsessed with file size to go that route 😜

@mikemaccana
Copy link
Contributor Author

Developit: it's literally only a few characters

if (!String.prototype.includes) {
  String.prototype.includes = function(search, start) {
    'use strict';
    if (typeof start !== 'number') {
      start = 0;
    }
    
    if (start + search.length > this.length) {
      return false;
    } else {
      return this.indexOf(search, start) !== -1;
    }
  };
}

See https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/includes . It's also way more readable than ye olde "if index is greater than or equal to zero".

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.

3 participants