irigsoft Posted February 17 Share Posted February 17 Hi. I try to replace some characters in one TuniEdit on clientside. That code i use, but not work properly (differer) on Desktop and on mobile Chrome: function keydown(sender, e, eOpts) { var val = sender.getValue(); var allowed = '!@#$%^&*_=.,/-[]{}|№"' + '0123456789' ; var c = event.key.charCodeAt(0);//event.code;//event.code;//e.keyCode || e.which;//e.getCharCode();//e.keyCode; var k = event.key; //if is used in mobile chrome - event.key is unidentified - https://stackoverflow.com/questions/17139039/keycode-is-always-zero-in-chrome-for-android if (k == "Unidentified" || c == 85 || c == 0) //for android chrome keycode fix { var val = sender.getValue(); c = val.charCodeAt(val.length - 1); k = val.charAt(val.length - 1); }; if (allowed.indexOf(k) > -1)// || val.length > 0) { c = String.fromCodePoint (c + 5); //change last char - not work correct val = val.substr(0, val.length-1); sender.setValue(val + c); //e.stopEvent() ; }; e.preventDefault(); } UniEdit - Triggers (ButtonEdit).zip Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 17 Share Posted February 17 Hello @irigsoft Can you check this post? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted February 17 Author Share Posted February 17 37 minutes ago, Sherzod said: Hello @irigsoft Can you check this post? thanks but this is different case. I try to explain my purpose: 1. must work on desktop and on mobile browsers (chrome and others) 2. code from above work proper on desktop browser because event.key return value and I can check point 3 3. event.key must be from array string that I insert on allowed 4. event.keyCode not return correct keycode when use allowed .fromCodePoint (event.keyCode), like example when I press * (Star), I get keyCode = 106 = m, but * (star) = 42. By this reason I can use event.keyCode ! 5. on mobile chrome I can't get event.key, for that reason i use : if (k == "Unidentified" || c == 85 || c == 0) //for android chrome keycode fix { var val = sender.getValue(); c = val.charCodeAt(val.length - 1); k = val.charAt(val.length - 1); }; and try to get last char on text field, but if is only one char, i get k=Unidentified and c=85 6. I don't use jQuery ! 7. I can use onkeyup because there is some delay and on fast char entering different replacement is executed ! On your examples all is based on event.key , like i explain event.key is not work on mobile chrome) Problem: how can I find out (on mobile chrome) which key was pressed when it is the first character in the text field on onkeydown event on mobile chrome Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 17 Share Posted February 17 I haven't looked at your test case yet. Try also using addEventListener to the dom element. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 17 Share Posted February 17 9 hours ago, irigsoft said: var c = event.key.charCodeAt(0); Just noticed you are using "window.event" - Seems this usage is deprecated and not recommended. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 17 Share Posted February 17 Once again, please clarify the statement of the problem, what should be done. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted February 17 Author Share Posted February 17 1 hour ago, Sherzod said: Once again, please clarify the statement of the problem, what should be done. 1. try chrome mobile browser (i use unigui - professional) with this code: function keydown(sender, e, eOpts) { var val = sender.getValue(); var allowed = '!@#$%^&*_=.,/-[]{}|№"' + 'zxcvbnmasdfghjklqwertyuiop' + 'ZXCVBNMASDFGHJKLQWERTYUIOP' + '0123456789' ; //Cancel the event //event.stopEvent() ; event.preventDefault(); event.stopPropagation(); var c = event.key.charCodeAt(0); var k = event.key; if (k == "Unidentified" || c == 85 || c == 0) //for android chrome keycode fix { var val = sender.getValue(); c = val.charCodeAt(val.length - 1); k = val.charAt(val.length - 1); }; if (allowed.indexOf(k) > -1) { c = String.fromCodePoint (c + 5); //change last char - not work correct //val = val.substr(0, val.length-1); sender.setValue(val + c); //e.stopEvent() ; }; e.preventDefault(); } 2. Try this for test: 2.1 use this code on desktop browser and write by hand asdfgh, that must give you as result 2.2 try to write same text but on mobile chrome browser, that will give you different result string. Last character is not converted ! asdfgh -> fxiklm is correct result string Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 17 Share Posted February 17 Ok, I will check. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.