Wednesday, 16 December 2020

Add / remove keywords in textarea doesn't work on cell phones (jquery)

Works fine on a computer. On a computer after you enter a word and press the space bar the word gets wrapped in a box and you get the option to remove it. On a cell phone nothing happens after your press the space bar. It also doesn't limit it to 5 words on a cell phone.

Working jsfiddle: http://jsfiddle.net/1hco43vr/

  $('#box a').on('click', function() {
    $(this).parent().parent().remove();
    console.log('remove disabled');
    if ($('#box ul li').length <= 5) {
      $('#type').prop('disabled', false);
    }
  });
}
$('#type').keypress(function(e) {
  if (e.which == 32) { //change to 32 for spacebar instead of enter
    var tx = $(this).val();
    if ($('#box ul li').length > 5) {
      $(this).val('');
      console.log('add disabled');
      $('#type').prop('disabled', 'disabled');
    } else {
      if (tx) {
        $(this).val('').parent().before('<li><span>' + tx + '<a href="javascript:void(0);">x</a></span></li>');
        closer();
      }
    }
  }
});


  


from Add / remove keywords in textarea doesn't work on cell phones (jquery)

No comments:

Post a Comment