jQuery mobile iscroll view : Cannot type in text box properly

941 Views Asked by At

In my jquery mobile ios phonegap application, i use iscroll. On using iscroll, text boxes behave weirdly (move up and down on entering each character).

I enabled iscroll in my app by,

Added following scripts:

 <script src="js/iscroll.js"></script>
 <script src="js/jquery.mobile.iscrollview.js"></script>

My page looks like,

 <div data-role="page" id="index">
    <div data-theme="a" data-role="header" data-position="fixed" data-id="footer" data-tap-toggle="false" data-transition="none">
    </div>
    <div data-role="content" data-iscroll>
      // following text field works weirdly 
      <input id="txtComment" placeholder="COMMENTS" value="" type="text" data-theme="b"/>  

    </div>
    <div data-role="navbar" data-position="fixed" data-theme="a" data-id="footer" data-tap-toggle="false" data-transition="none">
    </div>
 </div>

I tried adding the following code, but didn't work

 var selectField = document.getElementById('txtComment');
 selectField.addEventListener('touchstart', function(e) {
      e.stopPropagation();
 }, false);

How can i fix it?

Please help.

3

There are 3 best solutions below

1
On

Use this function with iscroll you can type in form fields.....

<script type="text/javascript">

    var myScroll;
    function loaded() {
        myScroll = new iScroll('wrapper', {
            useTransform: false,
            onBeforeScrollStart: function (e) {
                var target = e.target;
                while (target.nodeType != 1) target = target.parentNode;
                if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA')
                    e.preventDefault();
                }
            });
        }

    document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
    document.addEventListener('DOMContentLoaded', loaded, false);

</script>
1
On

same problem raised for me.just refresh your scroll using

setTimeout(function () { myScroll.refresh(); }, 1000);

by adding refresh at correct place you can overcome this problem.i have gone through many websites and tried a lot.its work me perfectly.

if it doesn't works then its Mobile version(android,ios) problem because scroll deosn't support. hope it will helps u.

0
On

Try:

in the Android Manifest activity: android:windowSoftInputMode = "adjustNothing"