How can I trigger text entry on number of characters entered

I have a text field, asking for a part number. Entry is terminated by enter/return on keyboard.

I also use a barcode scanner to enter the part number, which works great.
I'd like to avoid having to press enter/return button when using the scanner, which feeds a fixed number of characters.

How can I trigger the event without that extra button push when using scanner?

since when you scan it enters all number at one time you can have a setting to turn on a scanner option in the app which would just be a flag that when true it check the textfield for input and when it receives the part number it know to go to next function

edit
or if all number are same number of characters just have a function that checks the length of the string and if the correct number of characters are in it it proceeds to next function use string.len()

Length is what I want to trigger on so that no extra buttons have to be pushed before or after the scan.

The scanner acts like a keyboard, just no enter key.

I haven't found the right place to add the check for length.
I'm assuming it has to be in the onMasternum event.

I currently have an additional button event and then do all my checks on that button press. That's the button press I'm trying to avoid when using scanner, I.e. test that length is 12.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
local function onMasternum( event )
print("In onMasternum")
        if ( "began" == event.phase ) then
                masternumField.text=""
                hidekbButton.alpha=1.0
        elseif ( "ended" == event.phase ) then
                masternumField:setTextColor( 51, 51, 122, 255 )
                native.setKeyboardFocus( nil )
                hidekbButton.alpha=0
        elseif ( "submitted" == event.phase ) then
                masternumField:setTextColor( 51, 51, 122, 255 )
                native.setKeyboardFocus( nil )
                hidekbButton.alpha=0
        end
end
 
masternumField = native.newTextField( 50, viewrow+70, 220, 36, onMasternum )
masternumField.font = native.newFont( native.systemFontBold, 24 )
masternumField.text = "MasterNumber"
masternumField:setTextColor( 51, 51, 122, 45 )
masternumField.inputType = "number"

maybe try this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
local function onMasternum( event )
print("In onMasternum")
        if ( "began" == event.phase ) then
                masternumField.text=""
                checkInput = timer.performWithDelay( 500, function()
                             if string.len( masternumField.text ) == 12 then
                               timer.cancel(checkInput)
                               event.phase = "submitted"
                             end end, 0 )
 
                hidekbButton.alpha=1.0
        elseif ( "ended" == event.phase ) then
                masternumField:setTextColor( 51, 51, 122, 255 )
                native.setKeyboardFocus( nil )
                hidekbButton.alpha=0
        elseif ( "submitted" == event.phase ) then
                masternumField:setTextColor( 51, 51, 122, 255 )
                native.setKeyboardFocus( nil )
                hidekbButton.alpha=0
        end
end
 
masternumField = native.newTextField( 50, viewrow+70, 220, 36, onMasternum )
masternumField.font = native.newFont( native.systemFontBold, 24 )
masternumField.text = "MasterNumber"
masternumField:setTextColor( 51, 51, 122, 45 )
masternumField.inputType = "number"

just saw your edit

Thanks.
I'll try that tomorrow. Always nice to have more than one way to do things :)

views:2370 update:2012/2/12 11:34:30
corona forums © 2003-2011