When I used the Ionic View Android App, I noticed it has a feature I want. After you enter your email/password, when you hit the Keyboard’s GO button, the app acts as if the App Submit button was hit.
How do we setup our apps so that the app Submit thinks it was clicked when the user hits the keyboard GO button?
There are 2 requirements for this to work out of the box:
you need to put the input fields inside a <form ng-submit="submitLogin()">. Notice the ng-submit directive to the
you need to also include a <input> or <button> with type=submit. Be sure NOT to put a style with display:none on this button. If you want to hide it, use something like: <input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;"/>
Oh great, that works nicely. It makes sense for that to work inside a Form/Submit. Certainly a AngularJS feature more that Ionic. I thought I might have to do something with the submitLogin() function, but no, it just deals with it.
Most useful, I am sure others will find this of value.
This works for me to make the phone keyboard’s [GO] button activate my “Login” Submit button.
Further, the ng-click=“idSubmit()” code is relevant.
In the Controller for this screen, I have two features:
document.getElementById(“entry1”).focus();
Plain 'ol javascript to set cursor focus on my entry, notice it has BOTH an “id” for Javascript and an “ng-model” for AngularJS use.
To grab the user’s input value, in the controller, code the (ng-click=“idSubmit()”) function we gave our form as:
$scope.idSubmit = function() {
// using the “this” construct to pass in ng-model identified input data.
_id = this.id_entry;
}
Then, have your way with the _id value. Note that the “this” style is the conduit from Form to AngularJS.
I think it’s because you have ng-submit and also ng-click on the ‘Search’ button. So you should remove the ng-click from the button.
Here’s the angular docs about this: AngularJS – see Submitting a form and preventing the default action
To prevent double execution of the handler, use only one of the ngSubmit or ngClick directives.
Then, there’re a couple of other things:
Don’t use this inside an angular expression. Remember that angular expressions are evaluated in the context of an angular scope.
In your case, I think if you simply remove this, you should be ok.
OK you are awesome. I removed all this. and added an input field as you suggested. As described in the AngularJS docs the form will call the first ng-click function, since this was my clear function it cleard all inputs. So now I added an input before the button with the clear function which calls my search function. Here my new code in case someone else has the same problem. Thanks alot!
oh, this is a pretty neat hack that works, good thinking!
I don’t know for sure if this works, but try using the native type=reset for the ‘X’ button (also remove the ng-click, since form reset will be native html now), and keep type=submit for the search button. And I believe you won’t need the extra hidden button.
yes works! but in my case I need to call that function since there is more logic to be done when cleared. Else this would be a nice and easy solution. thx!
Anyone still having issues with the clear button. I have the keyboard working, however my ‘clear’ button still does not clear. Any feedback will be great.
Now that the go button is working, the keyboard won’t be dismissed after that. Only clicking on the Submit button will dismiss it. Any idea how to solve it? I am testing on Galaxy S5.
Thanks ! this works but only for text fields and search fields… it does not seem to work with Number Fields… it just shows a “next” button which does not do the “submit” function … Anyone else has this problem? can anyone confirm this behaviour?
I’m also having the same issue. The issue only occurs if I hit GO while focused on an input field that is either number or tel. If i’m focused on a text input it works fine.
I need only mobile number to send OTP on that number. If I use input as “text” I can see go button in keyboard but if I use “tel”/“number” it shows next button.