Can I change the input in the selection box?

I have a form with two selection fields for which I use select2 to match and tokenize what has ever been inserted into the field. I need to convert a list of inputs, separated by a new line, to a list, separated by a space (because IE does not do this automatically).

I have the following code that works fine with any fields <input>:

$('#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(clipped);
            return false; //cancel the pasting event
        });

but it does not work if #editor is a field <select>.

<form method="POST" action="/run" class="ui-widget" onsubmit=" return confirmSubmit(this, 'run',true) ">
    Editor:
    <select name="editor" id="editor" multiple style="width: 200px">
        <option>ALL</option>
    </select>
        <input type="submit" value="Submit">
 </form>

any idea what is missing?

+4
source share
1 answer

I’m not sure what to insert when choosing

A workaround may be as follows:

  • create invisible input
  • bind keydown event in select box
  • check if the key is a control key
  • ,
  • catch ,
  • select :)

:

0

All Articles