Paste a list to a select2 field and match each item in IE

If I paste a list of items separated with a new line character, Chrome converts the new line to a space and matches each item but IE truncates the list at the first new line character and only the first element is being pasted.

I've been trying suggestions to use the 'onpaste' method but it doesn't work with the new line character but I can't seem to get it working. it works fine with a comma or space.

$('body').on('paste', '#s2id_list-unitids .select2-input', function () { var that = this; setTimeout(function () { var tokens = that.value.split(/[\n]+/);$(that).blur(); $('#list-unitids').val(tokens, true); console.log($('#list-unitids').select2('val')); }, 1); });

Edit: Ok it does actually not work on my local environment even though i have no other code than the one give in the jsfiddle suggested in the comments.

<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>RiskCube Administration Console</title> <script type="text/javascript" src="javascript/jqGrid/jquery-1.8.3.js"></script> <script type="text/javascript" src="javascript/admin.js"></script> </head> <body> <input id="editor" type='text'> </body> </html>

and admin.js contains

$(document).ready(function () { var $editor = $('#editor'); var $clipboard = $('<input type="text" />').insertAfter($editor); $editor.on('paste', function () { var $self = $(this); setTimeout(function () { var $content = $self.val(); console.log($self.val()); $clipboard.val($content); }, 100); }); }); if (window.clipboardData) { $('#editor').bind('paste', function (e) { var clipped = window.clipboardData.getData('Text'); clipped = clipped.replace(/(\r\n|\n|\r)/gm, " "); //replace newlines with spaces $(this).val(clipped); alert("this is" + clipped); //this does not appear return false; //cancel the pasting event }); }

Category:javascript Time:2018-12-03 Views:1

Related post

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 4.621 (s). 15 q(s)