jquery - tokenSeparators in Select2 -
thanks in advance, 2 things:
1- how can take "enter" , "tab" keys token in select2?
this of code have.
$("#listavalores").val($("#listavalores").val().replace(/\;/g,',')) $("#listavalores").select2({ tags: true, tokenseparators: [';'], maximumresultsforsearch: -1, dropdowncss: {display:'none'}, });
first line transforming input data can used select2.
original input can sth this:
$("#listavalores").val("value1;value2;value3")
these values stored in db , loaded textbox transformed select2.
everything working expect, transform part:
tokenseparators: [';']
so accepts "enter" , "tab" keys token.
can help? tried ascii codes no luck.
2- plus, there tag disable spinner image? (since there no data being loaded don't need loading image appearing)
update 2:
i had success this:
$("#s2id_listavalores").on('keyup', function(e) { if(e.keycode === 13){ $("#listavalores").val($("#listavalores").val() + ';' + $("#s2id_autogen1").val()) } });
but $("#s2id_autogen1").val() not static , changing, kind of works once... plus, still need update results displayed. can with "refresh" on select2 div div changes it's id, , $("#s2id_listavalores").on('keyup', function(e) event not work.
i solved problem recursion function:
//init select2 field: initmultiselect(tsel); function initmultiselect(tsel) { tsel.select2('destroy'); tsel.select2({ tags: true, tokenseparators: [',', ' ', ';'], dropdowncss: {display:'none'} }); //manual add new values enter (function (t) { $('#s2id_' + t.attr('id')).on('keyup', function(e) { if(e.keycode === 13){ //add new value t.val(t.val() + ',' + $('#s2id_' + t.attr('id') + ' input ').val()); //refresh select2 initmultiselect(t); //get focus select2 last position t.select2("close"); t.select2("open"); } }); })(tsel); }
Comments
Post a Comment