javascript – How to get Next button on android softkeyboard in place of Go Button in phonegap-ThrowExceptions

Exception or error:

I am developing Phonegap application and have many inputs in application form. I am getting Go button on keyboard of android.I want to replace go button with next button. As clicking on Go button (as shown in image) submits form.
In android native we can specify next button in XML but for Phonegap how to specify next button in place of go button.?
Some Samsung devices have by default Next Prev button on top.
By Default there is Go button. I need Next but in Phonegap

By Default there is Go button. I need Next but in Phonegap. is there any plugin for specifying that for android.

How to solve:

Having a “Next” button instead of “Go” is not possible with Android as of now.

Android will always display “Go” button for form input fields. “Go” is basically reflecting the same behavior as of an “Enter” button on a normal browser & keyboard. You can achieve through below code:

if (event.keyCode == 13) {
           //Handling "Go" Button to move to next input field
       }

OR

If your input fields are more, then data-dependency will be best solution.
If you want to prevent users from submitting the form, you can put required validations on the form using javascript, where you can specify data-dependency inside input field with required, which helps move cursor to a particular field which you specified in data-dependency.

<input type="text" id="first" data-dependency="second" />
<input type="text" id="second" data-dependency="third" />
<input type="text" id="third" />

It move focus to next fields in form until its your last field. Once last field reaches you can allow it to act as enter. So basically Go will keep moving focus to next fields until its your last field & then will submit the form.

###

Its been said that if have input fields without or outside the form tag means you will get next button as tab button

As far as i know there is no proper solution to get next button instead of go . There are only workarounds do it. Most common one is to capture the ‘Go’ button as enter key(keycode ’13’) in javascript and do your thing.

$('selector').on("keydown",function(event){
       if (event.keyCode == 9) {
           //you got tab i.e "NEXT" Btn
       }
       if (event.keyCode == 13) {
           //you got enter i.e "GO" Btn
       }
});

for tab button instead of enter

There has been also sources that already discusses these GO Vs NEXT button

###

You can simply use the following logic to let users focus on the next input field. This is a better approach, which I used in my one of the PhoneGap applications, as currently there are no 3rd party plugins which offer such functionality.

x$('#input1').on('keyup', function(e) {
 var mEvent = e || window.event;
 var mPressed = mEvent.keyCode || mEvent.which;
 if (mPressed == 13) {
  // On enter, go to next input field
   document.getElementById('input2').focus();
 }
return true;
});

###

Have you tried using the tabindex parameter on your input fields?

The default action of the keyboard should be to show next if tabindex is detected.

Example:

<input name="first" tabindex="1" /> //should show next

<input name="second" tabindex="2" />  //should show next

<input name="third" tabindex="3" />  //should show go

###

EditText android:imeOptions= “actionNext”

Leave a Reply

Your email address will not be published. Required fields are marked *