ionic-team / ionic-plugin-keyboard

Ionic Keyboard Plugin for Cordova
Apache License 2.0
610 stars 274 forks source link

Support for setting iOS UIReturnKeyType #54

Open anemitoff opened 9 years ago

anemitoff commented 9 years ago

We really need a feature to allow an ionic application to select whether the return key on the iOS keyboard says "GO" or one of the other allowable values such as "Next" (see below for other options). I know others have requested this functionality in the ionic forums but it seems that this keyboard plugin is the proper target for such a request.

The allowable values are: typedef enum : NSInteger { UIReturnKeyDefault , UIReturnKeyGo , UIReturnKeyGoogle , UIReturnKeyJoin , UIReturnKeyNext , UIReturnKeyRoute , UIReturnKeySearch , UIReturnKeySend , UIReturnKeyYahoo , UIReturnKeyDone , UIReturnKeyEmergencyCall , } UIReturnKeyType;

antonshevchenko commented 9 years ago

+1

ghost commented 9 years ago

I don't think this is currently possible considering the app's hosted in a UIWebView. There doesn't seem to be any way to convince WebKit to use a specific return key for a field, and there's definitely no way of doing it through Objective-C.

All the plugin has access to is a UIWebView and a UIViewController. Maybe some kind of dirty hack could be implemented to force UITextFields associated with DOM elements to have a certain key type, but I doubt this would be particularly stable or future proof.

antonshevchenko commented 9 years ago

I noticed that putting an <input> field in <form>s will automatically adjust the keyboard's return key.

For instance, the following would display the word "Search" in the return key:

<form>
  <input type="search">
</form>
ghost commented 9 years ago

Yes this seems to work for simple use cases, the main issue is achieving the 'next' functionality you can do in native iOS apps. I don't think this is currently possible without resorting to private APIs as Safari uses an accessory bar to achieve this instead.

tlancina commented 9 years ago

Duplicate of https://github.com/driftyco/ionic-plugins-keyboard/issues/20. I spent a lot of time on this and even with private APIs couldn't get it to work. As @lyptt said, the 'next' functionality for the return key doesn't exist in mobile Safari (as far as I know), instead it uses the accessory bar.

I'm going to be revamping a lot of keyboard stuff soon so I'll take another look, but closing this for now.

lbickston commented 9 years ago

I see this was reopened on April 9. Any progress on this?

moultz commented 9 years ago

Looks like this was reopened, any progress/update?

tlancina commented 9 years ago

It was reopened in hopes that WKWebView would expose more access to the keyboard (or implement UITextInputTraits), but that wasn't the case. As far as I know this is still not possible, but I would really love to be wrong!

iischajn commented 9 years ago

+1

janpio commented 9 years ago

+1

daco commented 9 years ago

+1

bensinclair commented 8 years ago

+1

feliperbroering commented 8 years ago

+1

Findiglay commented 8 years ago

+1

gkucsko commented 8 years ago

+1

smakys commented 8 years ago

+1

FabricioFFC commented 8 years ago

+1

josenicomaia commented 8 years ago

+1

egkozlov commented 8 years ago

+1

b264 commented 8 years ago

+1

triasrahman commented 8 years ago

+1

razorcd commented 8 years ago

+1

EmilioVillante commented 8 years ago

+1

jasongilmour commented 8 years ago

+1

donaldG21 commented 8 years ago

+1

popaprozac commented 8 years ago

+1

bengro commented 8 years ago

+1

kernelLove commented 8 years ago

+1

TawabG commented 8 years ago

+1

avatsaev commented 8 years ago

the fact that is issue is still open shows how much of a garbage framework ionic is

josenicomaia commented 8 years ago

@avatsaev It's simple. Just PR it!

plenartech commented 8 years ago

+1

EralpB commented 8 years ago

+1

yaswant-dowlut commented 8 years ago

+1

At least we should have the ability to switch to the next field when the return key is clicked, and perform an action when the return key is hit on the last field.

yaswant-dowlut commented 8 years ago

A workaround to get the behaviour I described in my previous comment working is as follows. Note that I have assumed that jQuery has been included in the project. But this example can also be adapted to work with jqLite alone as well.

Add the following line in config.xml:

<preference name="KeyboardDisplayRequiresUserAction" value="false"/>

Create the following directive:

.directive(‘iosReturnHandler', function() {
  return {
    restrict: 'A',

    link: function(scope, element, attrs) {
      element.keyup(function(e) {
        if (e.which == 13) {
          var nextSibling = element.next('input');

          if (nextSibling.length == 0) {
            scope.$apply(function() {
              scope.$emit(‘ios-last-return-clicked');
            });

            return;
          }

          nextSibling.focus();
        }
      });
    }
  }
})

Then add the directive to input fields on which you want the return key of the keyboard to be handled:

<input type=“text” id=“input1” ios-return-handler />
<input type=“text” id=“input2” ios-return-handler />
<input type=“text” id=“input3” ios-return-handler />

This will cause the focus to be automatically changed to the next input when the return button is clicked on the keyboard. When the last input is reached and the return button is clicked again, the event ios-last-return-clicked will be emitted which you can catch in your controller to perform some action.

I hope this helps.

vmunich commented 7 years ago

+1

kyle-apex commented 7 years ago

+1

If it's useful for anyone, I created the following directive that works to tab when "Go" is clicked in RC4 when adding a tabOnGo directive to ion-input.

@Directive({
    selector: '[tabOnGo]'
})

export class TabInputDirective {

  inputRef: TextInput;
  constructor(inputRef: TextInput) {
    this.inputRef = inputRef;
  }

  @HostListener('keydown', ['$event']) onInputChange(e) {
    var code = e.keyCode || e.which;
    if (code === 13) {
      e.preventDefault();
      this.inputRef.focusNext();
    }
  }
}
adamiprinciples commented 7 years ago

+1

ghost commented 7 years ago

@kyle2829 Where are you importing the TextInput type?

kyle-apex commented 7 years ago

@emersonstewart import {TextInput} from 'ionic-angular';

ghost commented 7 years ago

Ah, easy enough. Thanks!

ddoerr commented 7 years ago

+1

This is super important for our project!

THEDOWNCOUNTRY commented 7 years ago

Any Solution on this?

entomb commented 7 years ago

please please please please please please

jdnichollsc commented 7 years ago

+1

jdnichollsc commented 7 years ago

What do you think @EddyVerbruggen?

tanohzana commented 7 years ago

+1