Bug? Can't type in MobileTextField until I press the (X) icon

This is such a weird bug. It only happens on a real iOS device, not the simulator.

When I click into a blank MobileTextField to edit it, the cursor appears to the left as expected. A small circular “X” icon appears on the right.

I can’t type into the field until I press the X. Trying to type does nothing. Once I press the X, then I can type.

It seems to only happen if the MobileTextField starts off blank.

My testers pointed this out to me first since it’s only on real devices. Based on when their feedback began, I feel like it coincided with Xojo 2026 release but I’m not positive.

Has anyone else experienced this? Any workarounds?

I’ve found a (very annoying) workaround.

Public Sub removeClearButton(tf as MobileTextField, mode as integer)
Declare Function sel_registerName Lib “/usr/lib/libobjc.A.dylib” (name As CString) As Ptr
Declare Sub objc_msgSend_setInt Lib “/usr/lib/libobjc.A.dylib” Alias “objc_msgSend” (obj As Ptr, sel As Ptr, value As Integer)

Var h As Ptr = tf.Handle
If h = Nil Then Return

Var selSetClear As Ptr = sel_registerName(“setClearButtonMode:”)
objc_msgSend_setInt(h, selSetClear, mode)
End Sub

Then on focusreceived, remove it and put it back right away:

modClearButton.removeClearButton(me, 0)
modClearButton.removeClearButton(me, 1)

I guess I’m going to have to subclass MobileTextField, make this change so it applies to every control for the subclass, and rework every MobileTextField control in my app…. ugh.

Unless anyone has some insight into why this is happening?

I take it back. I think the “solution” was that the default text was a space. Not the above code. Still investigating.

What code do you have that sets the text in this field and in what events? For instance, changing the text in the textchanged event can cause this issue

In this particular text field, nothing. It’s just an empty search field that does not get set or do anything until you type into it.

But I have the same issue on other text fields where they get set to a blank and then you can’t type into them until you click the X.

I’m going to try to make an empty project with just a text field and see if it reproduces. If it does, I’ll submit a bug report.

My very simple demo app with just text fields on the first screen does not have this issue.

So I’ll have to see if I’m doing something differently in the main app that is potentially causing this.

In case anyone is curious: this must be something specific to my app.

I tried adding iOSDesignExtensions to my test app, and I tried other things like putting the screen into a tab bar to replicate the app with this issue, and even copied in the exact screen to the test app. None of that triggered it in the test app.

So I’m kind of stumped.

Ok, so here’s what I found out… from the iOS side of things…

This is a known iOS behavior, not user error.

What’s actually happening

The UITextField has focus, but text insertion is blocked until the clear button fires an edit event. Pressing the clear button forces an internal state reset, which is why typing suddenly works.

Most common causes

Mutating the text while the field is first responder. In Xojo-speak that’s “programmatically changing the text while the field has focus”.

Things like formatting the text on every keystroke will do this (like if you’re trying to force a certain format). The problem is that the “selection” needs to keep up with your changes, so you’d need to

  1. Get the selection
  2. Change the text
  3. Restore the selection

Other common culprits are:

  • changing field parameters while the field has focus
  • Toggling the Enabled property while the field has focus
  • Calling SetFocus when the field already has focus

Something that sometimes works to fix it is to set the text to the same value it already is when the field gets focus. That is:

TextField1.text = TextField1.text

In the GotFocus event.

Thanks. I tried the me.text = me.text thing but it didn’t work.

I think it may be significant that it only happens when the field is blank. If the default value is a space it works.

Maybe there some way that I can use a declare to mimic pressing the “X” when field starts off blank?

One thing I notice that may be a hint is the “Hint” text does not show up either until I press the X to clear the field. Even though the field starts off blank.

I managed to workaround by subclassing MobileTextField and detecting CHR(0) as the text on Opening. When the CHR(0) state is detected, I flip a boolean to TRUE that indicates “don’t run TextChanged right now”. Then I switch the Text to be a space and set a flag that the text was modified.

Then, later on keyDown, if the text was modified I clean out the leading space but leave the key that the user typed. This assures the Text property is never set to ““, because that makes it uneditable again.

All of this requires a new event definition where I fire any custom TextChanged events since the subclass textChanged event is dedicated to making sure it doesn’t treat the initial “ “ as a real change.

Then I changed all my MobileTextFields to the subclass.

It was a major pain but at least I can release the app now with this workaround.

If anyone else encounters this issue let me know and I will post the subclass in its entirety.

1 Like

I marked this as a solution, but deep down it still feels like a Xojo bug. I can’t reproduce it in a simple project, though, or I would submit a bug report.

So the field has a chr(0) in it then? That would make perfect sense. Chr(0) is a string terminator, so even if the user was typing, the characters would not show.

That sounds like your real problem.

You can see this behavior in a desktop app if you join two strings with a chr(0) and then put them in a text field. You’ll only see the first word even though they’re both technically there.

1 Like

Yeah, it’s strange. I can’t figure out why it would have CHR(0), and why that would only be on a real device and not the simulator. And I discovered that my workaround isn’t really 100% working.

So I will mark this unsolved and see if I can find a way to deal with the CHR(0) and remove it.

If you save your project as text, check the default value of the text field.

Greg, thanks for all the suggestions. I checked one of my screens in a hex editor but it looks like the text property just = ““.

I have a good enough workaround for now subclassing MobileTextField (the only issue is that it doesn’t show the hint until you click into the field). So at least we can release the app. Again, if anyone finds they are experiencing this error let me know and I can help.

I think I will have to make a pared down version of my project that still shows the bug in action and send it with a bug report.