iOS Question SubString2 not working well on ios 8

Shay

Well-Known Member
Licensed User
Longtime User
Strange thing
I have the code below which limit phone number to 10 digits
on IOS 7 it is working fine, it is limiting the number to 10 numbers
on IOS 8, I managed to enter 11 digits (maybe even 12, I don't have the DB in front of me)

B4X:
Sub EditText6_TextChanged (Old As String, New As String)

    If New.Length > 10 Then
     EditText6.Text = New.SubString2(0, 10)
    End If
   
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is not related to Substring.
It is related to how the internal text field handles the text update.

This code should work:
B4X:
Sub TextField1_TextChanged (OldText As String, NewText As String)
   CallSubDelayed(Me, "CutText")   
End Sub

Sub CutText
   If TextField1.Text.Length > 10 Then
  TextField1.Text = TextField1.Text.SubString2(0, 10)
  End If
End Sub
 
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
How can I make this generic
meaning if I have many TextFieldXXX with sizes YYY
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Try this:

B4X:
Sub TextField1_TextChanged (OldText As String, NewText As String)
   CallSubDelayed3(Me, "CutText",TextField1,10)  
End Sub
Sub CutText(Tf As TextField,MaxLength As Int)
    If Tf.Text.Length > MaxLength Then
        Tf.Text = Tf.Text.SubString2(0,MaxLength)
    End If
End Sub
 
Upvote 0
Top