How to set the Keyboard Type

In Xcode you can set a keyboard type for UITextfields.
For example if you want num only, you can set it to UIKeyboardTypeDecimalPad

How can this be done in Xojo iOS?

BTW there are several keyboard types. This is very important to has this ability imo

I have not touched the iOS stuff at all, but I’m calling it now: declare required at this time.

In the inspector :slight_smile:

Yep. Added late in the beta.

Bummer … completely overlooked this. :slight_smile:

Be aware that the simulator has a bug and does not show anything but the US keyboard…

Actually I had this too in Xcode. An Apple dev explained this at the Apple Developer Forum.
It seems this is not a bug but a feature.

As long you do not start to enter anything with your hardware keyboard, it will use the iOS keyboard. Ones you used the hardware keyboard it will not show the iOS keyboard anymore unless you active this again in the Emulator menu.
This workflow can speedup testing your app - thats the idea behind it.

OK, I misread your line here.
I was referring to the iOS keyboard not always showing up when needed - this seems to be a bug, but it isn’t. :slight_smile:

But you are right, it always uses a US Keyboard layout.

[quote=151706:@Christoph De Vocht]OK, I misread your line here.
I was referring to the iOS keyboard not always showing up when needed - this seems to be a bug, but it isn’t. :slight_smile:

But you are right, it always uses a US Keyboard layout.[/quote]

I don’t know yet what the issue is exactly. The simulator Preferences let you add another keyboard such as French, show it, but yet the keyboard that shows is still US.

As long as it does not happen on the device, it’s alright, though.

The physical keyboard precedence I saw in the iOS Swift course. Actually, the simulator behaves just like the device. If you add a blue tooth keyboard to a device, it takes precedence just the same way.

I disconnected it in the simulator, though. I need to figure as closely as possible how it will look on the device. Especially since people using a keyboard with an iPhone must be extremely rare :wink:

I’ve got some textfields that require integer input so I’ve specified the NumberPad. This works correctly in the simulator on an iPhone (portrait). But in the simulator on an iPad (portrait) I get a full keyboard. Haven’t tried it on an actual device yet but wanted to confirm that I’m just seeing a “feature” of the simulator that won’t happen on an actual iPad.

You need to change the simulator device language too. Then the correct keyboard for your language is shown.

Are you sure it is not iPad’s NumberPad keyboard? This looks different than the very limited iPhone NumberPad type, but on a closer look you’ll see instead of characters mathematical symbols and signs are available. At least here on the Simulator it works. If it should not for you: What Xojo version, what XCode/OS X version do you use?

Thanks, Ulrich. I’m using the latest versions of everything.

Damn. I’m finding other threads about this on StackOverflow. Looks like, on an iPad, I’ll need to code around this to accept only 0-9 input to keep the user from crashing the app.

Hating to reinvent the wheel, can someone point me to a code snippet to do this? :wink:

I’m sorry, this is no snippet at all, but iOSLib’s iOSLibTextField features all the events, including the ShouldNotChangeCharacters Event. The funny name because you can return true if ReplacementText is not a number.
It should be possible to build a stand-alone version too, but I currently don’t have the time, sorry.

The text change event fires on every keypress in a textfield so you can just check if right(1) isa number
if not rip it off and throw it away
something like

  const numbers = "1234567890"
  if me.text = "" then return
  dim lastCharIn as text
  lastCharIn = me.text.right(1)
  if numbers.IndexOf(lastCharIn) >= 0 then
    me.text = me.text.Left( me.Text.Length - 1 )
  end if

Thanks, Norman! I’m used to the old String functions and hadn’t thought about how to do this with Text.