最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Form submit button event is not captured when keyboard is up iOS 7 - Stack Overflow

programmeradmin4浏览0评论

I'm building an web app using cordova targeting iOS. I have this form

<form id="formID">

  <div class="row">
    <input type="text" name="something1" placeholder="something1" class="form-control" required maxlength="26" />
  </div>

  <div class="row">
    <input type="text" name="something2" placeholder="something2" class="form-control" pattern=".{6,6}" required />
  </div>

  <div class="row">
    <input type="submit" value="Submit" class="button btn-primary" />
  </div>

</form>

In my javascript I then have a listener for the submit event.

My problem is that when the keyboard is showing in iOS, clicking the submit buttons doesn't always trigger the submit event. Somethimes it works the first 2 times but then stops working. Anyone that has run in to this before?

As it is now you may need to first click "Done" on the keyboard (making it disappear) and then use the submit button. Or, click the submit button with the keyboard showing which will make the keybpoard hide and then click the submit again.

Any ideas?

EDIT

It works fine on iOS 6, but on iOS 7 the submit button doesn't trigger an event after the first 2 clicks.

I'm building an web app using cordova targeting iOS. I have this form

<form id="formID">

  <div class="row">
    <input type="text" name="something1" placeholder="something1" class="form-control" required maxlength="26" />
  </div>

  <div class="row">
    <input type="text" name="something2" placeholder="something2" class="form-control" pattern=".{6,6}" required />
  </div>

  <div class="row">
    <input type="submit" value="Submit" class="button btn-primary" />
  </div>

</form>

In my javascript I then have a listener for the submit event.

My problem is that when the keyboard is showing in iOS, clicking the submit buttons doesn't always trigger the submit event. Somethimes it works the first 2 times but then stops working. Anyone that has run in to this before?

As it is now you may need to first click "Done" on the keyboard (making it disappear) and then use the submit button. Or, click the submit button with the keyboard showing which will make the keybpoard hide and then click the submit again.

Any ideas?

EDIT

It works fine on iOS 6, but on iOS 7 the submit button doesn't trigger an event after the first 2 clicks.

Share Improve this question edited Jun 23, 2014 at 15:10 Oscar asked Jun 19, 2014 at 12:37 OscarOscar 3833 silver badges13 bronze badges 1
  • I've seen similar issues, but usually when trying to dismiss the keyboard by clicking a control that doesn't normally respond to clicks or taps. Another good test is to see if your page responds the same way using Mobile Safari; that will help you isolate whether this is specific to Cordova, or more general to UIWebkit. – Palpatim Commented Jun 19, 2014 at 15:02
Add a ment  | 

1 Answer 1

Reset to default 6

So I solved the problem I was having. As stated in the question it worked fine for ios6 and android. But for ios7 I noticed when I increased the height of the text fields above the submit button I got the bug described above. When I didn't add any non-default styling that effected the height of the elements above the submit button worked. Weird right.

But then I read this question.

So instead of having a submit button and having my script wait for the submit event to fire, I changed the button to a link and listened for a touchend event. Bam, it worked like a charm.

$(document).on('touchend', 'form #button', function (e) {
    $('#formID').submit();
});

So I let this event bypass and trigger the submit event so that clicking the "Go" button on the keyboard still trigger a submit function.

发布评论

评论列表(0)

  1. 暂无评论