tags-input icon indicating copy to clipboard operation
tags-input copied to clipboard

Ensure tags must fit pattern before adding them

Open mikemaccana opened this issue 8 years ago • 5 comments

Fixes #20

mikemaccana avatar Apr 10 '17 10:04 mikemaccana

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

thomasdegry avatar May 16 '17 15:05 thomasdegry

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

developit avatar May 16 '17 15:05 developit

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

mikemaccana avatar May 17 '17 17:05 mikemaccana

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

developit avatar May 21 '17 13:05 developit

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".

mikemaccana avatar May 22 '17 09:05 mikemaccana