Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

native.newTextField phase doesnt go to 'Ended' or 'Submitted' when clicking out of it.
Started by edualc Apr 03 2019 05:16 PM

2 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

edualc

[GLOBAL: userInfoPane.html]
edualc
  • Enthusiast

  • 60 posts
  • Corona SDK

hello all,

I'm using native.newTextField at the bottom of the screen to let the user enter his/her name and save it to a score file. When the field is clicked I move the field to the top so it sits above the virtual keyboard of a phone/tablet.

Now when the field is clicked the event.phase is 'begin' . when a name is typed in the event.phase is 'edifting' (for each character.

if the user hits <Enter> it then goes to a phase of 'submitted' (sometimes 'ended') which allows me to move the field back to the bottom of the screen.

 

However if the user simply clicks out of the native.newTextField it doesnt go into a phase of 'ended' or 'submitted'

Even if I click on another button, the field is still up there awaiting a <Enter>.

 

Is there a proper way for the phase to go to 'ended' when clicking out of it ? 
I can move the field back down in all other button/pictures/icon EventListeners but it's pretty tedious !

 

thanks !

 

12:04:55.994  here is lncurrentUserField> fr <> fr <> began
12:04:57.518  here is lncurrentUserField> fre <> fr <> editing
12:04:57.667  here is lncurrentUserField> fred <> fr <> editing
12:05:05.317  here is lncurrentUserField> fred <> fr <> submitted        --<< only when hit <Enter>
 
function lncurrentUserField(event)
      print ("here is lncurrentUserField>",currentUserField.text,"<>",glob.currentUserSaved,"<>",event.phase)
      if ( event.phase == "began" and string.upper(currentUserField.text) == "ENTER YOUR NAME") then
            currentUserField.text = ""
            currentUserField.y = screenCenY - 50
      elseif ( event.phase == "began" and string.upper(currentUserField.text) ~= "ENTER YOUR NAME" ) then
            currentUserField.y = screenCenY - 50


      elseif ( event.phase == "ended" or event.phase == "submitted" ) then          --<< it comes here if hit <Enter>
            fnmoveCurrentUserFieldDown()                                            -- but not if click outside
      end
end


currentUserField = native.newTextField( screenCenX , screenBot -20 , 200, 20 )


currentUserField:addEventListener( "userInput", lncurrentUserField )

 



[TOPIC: post.html]
#2

Dave Yang

[GLOBAL: userInfoPane.html]
Dave Yang
  • Enthusiast

  • 97 posts
  • Corona SDK

Try adding an invisible background to initiate the "ended" phase, something like this:

 

local cX, cY = display.contentCenterX, display.contentCenterY
 
local bg = display.newRect(cX, cY, display.actualContentWidth, display.actualContentHeight)
bg:setFillColor(0,0,0,0)
bg.isHitTestable = true
 
bg:addEventListener("touch", function() native.setKeyboardFocus(nil) end)
 
---------------------------------------------------------------------------
 
local y = cY - 150
local enterYourName = "ENTER YOUR NAME"
 
local currentUserField = native.newTextField(cX , y , 300, 40)
currentUserField.text = enterYourName
 
---------------------------------------------------------------------------
 
local function lncurrentUserField(event)
    local p = event.phase
 
    if p=="began" then
        if string.upper(currentUserField.text)==enterYourName then
            currentUserField.text = ""
        end
        currentUserField.y = y - 50
 
    elseif p=="ended" or p=="submitted" then
        native.setKeyboardFocus(nil)
        currentUserField.y = y
    end
end
 
currentUserField:addEventListener( "userInput", lncurrentUserField )

 

Does this work?

 

Dave



[TOPIC: post.html]
#3

edualc

[GLOBAL: userInfoPane.html]
edualc
  • Enthusiast

  • 60 posts
  • Corona SDK

native.setKeyboardFocus(nil) works a treat. 

 

And I don't even need an extra invisible background as .. I have a background ! So i just added a listener to it.

 

I'm just surprised we have to do this, that Corona doesn't notice that the focus is nolonger on the field .. 

 

but it's working well, thank you !




[topic_controls]
[/topic_controls]