I am trying to limit the number of characters in a number of my text fields.
I am using this code:
local function textfieldHandler( event ) if event.phase == "editing" then print( "In editing mode" ) local fieldText = event.text if string.len(fieldText) \> 22 then print( "String too long" ) fieldText = string.sub(fieldText, 1, 22) print( "fieldText value: ", fieldText ) event.text = fieldText print( "event.text value: ", event.text ) end end end
Several of my text fields call this handler.
When I type in the fields, I see the print statements being made. And I see both values being set as expected.
But the text field itself never updates. And if I click through, the .text value being saved is the unedited version.
If I change the event.text = fieldText line to formTextField1.text = fieldText , it works fine. The text field updates as expected. But then covers just that one field.
Why is the event.text version of the line not setting the field?