1

I thought that this would add a space after each 4 chars, but instead, after the fourth digit the input is set to ''. Why?

keyUp: function(e) {
    if (e.target.value.length === 4) {
      var value = e.target.value + ' ';
      e.target.value = value;
    }
    else if (e.target.value.length === 9) {
      e.target.value += ' ';
    }
    else if (e.target.value.length === 14) {
      e.target.value += ' ';
    }
  },
Paul Byrne
  • 1,563
  • 18
  • 24
  • Your code works as intended for me. Could it be some ember thing? As a sidenote: it's annoying when trying to use the backspace when you mistyped a digit, since you can't go back beyond the last space since it'll get added again all the time. So best to add a check if the key pressed is the backspace. – Shilly Oct 07 '15 at 13:08
  • I think it works: http://jsfiddle.net/ct3g5oc4/ – slomek Oct 07 '15 at 13:09
  • Yeah I know what you mean, funny it isn't working in Ember. Well thanks anyway :) – Paul Byrne Oct 07 '15 at 13:19

0 Answers0