native.newTextField() can't be removed!?

I feel stupid… not only that I had to program some “fake newTextField” routines to not constantly have to go back to the device for placement and usability tests…

No … I also try to find how to remove those fields from the display since an hour…

Is there a bug that you can remove those?

It s mentioned that they do not behave to standard display object hierarchy… ok…

Can we please get a replacement function in the simulator (which looks like… but not actually needs to be the original)

And please document how to deallocate them… Just moving them to hide them … is ugly… [import]uid: 6928 topic_id: 1337 reply_id: 301337[/import]

Try using yourGroup:remove(yourTextFieldObject), where “yourGroup” is a group that contains the text field.

-Gilbert [import]uid: 5917 topic_id: 1337 reply_id: 3627[/import]

May I ask you to try that? I bet you never did…

I would not file a bug if that would work…

And obj.parent:remove(obj) or obj:removeSelf() would be a better general recommendation for display objects … Later on still used by devs in the forum and still not documented it seems.

My guess is that they are NOT in “yourGroup”. They do not obey to the display object groups… But there should be a way to deallocate or to remove them from the stage… But I repeat myself… [import]uid: 6928 topic_id: 1337 reply_id: 3628[/import]

What’s up!? Can we please continue to evaluate this problem and having it fixed? [import]uid: 6928 topic_id: 1337 reply_id: 3734[/import]

Your guess is right OderWat, they are not in “yourGroup”, that’s why you cannot remove them

If you insert a text field in a group, and set the x coordinate of the group to 320, the text field should not show up on the screen, yet it does…

I also noticed that whenever i tap on the field to type, on the Organizer console i get the message:
Mobile Safari warning, Safari got memory level warning, killing all documents except active…
There are no other elements, other than the text field, to consume memory

[import]uid: 6459 topic_id: 1337 reply_id: 4025[/import]

The native.newTextBox has the same problem

You insert it in a group, you place the group off the screen, but the TextBox shows up as if group.x were 0

[import]uid: 6459 topic_id: 1337 reply_id: 4028[/import]

Yep… This is “documented” and was expected by me (hence their “does not obey to object hierarchy”).

I do not care about this… I care about a way to remove it from the stage and deallocate it.

The whole “my guess” part tries to give Gilbert a “hint” … and he may need to inform himself about the facts before he answers a “bug report” that way. I am really getting upset about this kind of replies lately. I still try to be calm and not return the favor to obviously.

Still there is no bug id assigned or any other helpful information given…

I want a big “escalation” button which sends stuff to actual developers which care about their baby… [import]uid: 6928 topic_id: 1337 reply_id: 4041[/import]

Sorry about that. I escalated this. It’s filed as bug #301.

NativeUI objects can’t be removed in any way. You must hide them using isVisible=false.

I’ve filed the bug to provide a way to remove them.

Thanks,
Gilbert [import]uid: 5917 topic_id: 1337 reply_id: 4059[/import]

Thank you Gilbert! Much appreciated! [import]uid: 6928 topic_id: 1337 reply_id: 4066[/import]

@OderWat, We are working to resolve bugs like this and bugs that crash the simulator/device ASAP. [import]uid: 7559 topic_id: 1337 reply_id: 4084[/import]

@OderWat,

Can you provide some sample code showing the problem where the textField is not removed from the group?
I’m playing with a fix but can’t find a test case under Beta 6 where the native.textField is not removed.

Thanks,
Tom [import]uid: 7559 topic_id: 1337 reply_id: 4161[/import]

Hey Tom,

I sent you this test code in an email.

[code]
myGroup = display.newGroup()

–Add a text field to the screen
myTextField = native.newTextField( 0, 0, display.contentWidth*.6, 25)
myGroup:insert(myTextField)
myTextField.x = display.contentWidth/2 - myTextField.width/2
myTextField.y = display.contentHeight/3

–Add a button
myButton = display.newGroup()
buttonColor = display.newRoundedRect(0, 0, 200, 40, 20)
buttonColor:setFillColor(255, 0, 0)
myButton:insert(buttonColor)
buttonText = display.newText(“Remove TextField”, 0, 0, native.systemFontBold, 14)
buttonText:setTextColor(255, 255, 255)
myButton:insert(buttonText)
buttonText.x = myButton.width/2
buttonText.y = 18
myButton.y = display.contentHeight/2
myButton.x = display.contentWidth/2 - myButton.width/2

–Add a button2
myButton2 = display.newGroup()
button2Color = display.newRoundedRect(0, 0, 200, 40, 20)
button2Color:setFillColor(255, 0, 0)
myButton2:insert(button2Color)
button2Text = display.newText(“Hide TextField”, 0, 0, native.systemFontBold, 14)
button2Text:setTextColor(255, 255, 255)
myButton2:insert(button2Text)
button2Text.x = myButton2.width/2
button2Text.y = 18
myButton2.y = myButton.y + myButton.height + 20
myButton2.x = display.contentWidth/2 - myButton.width/2
function dismissTextField(event)
if(event.phase == “ended”) then
myGroup:remove(myTextField)
–myTextField = nil
buttonText.text = “Removed?”
end
end

myButton:addEventListener(“touch”, dismissTextField)
function hideTextField(event)
if(event.phase == “ended”) then
myTextField.isVisible = not myTextField.isVisible
button2Text.text = “Show TextField”
end
end

myButton2:addEventListener(“touch”, hideTextField)
[/code] [import]uid: 5917 topic_id: 1337 reply_id: 4162[/import]

Hi Gilbert,

Thanks for the code. The problem is this code works in Beta 4, 5, and 6. If I click on the “Remove TextField” button, the textField disappears (as it should).

This code does have a problem because there is no listener for the textField and therefore no way to dismiss the keyboard (which hides the buttons).

I added this code to remove the keyboard after pressing Return.

local function fieldHandler( event )  
  
 if ( "began" == event.phase ) then  
 -- This is the "keyboard has appeared" event  
 -- In some cases you may want to adjust the interface when the keyboard appears.  
  
 elseif ( "ended" == event.phase ) then  
 -- This event is called when the user stops editing a field: for example, when they touch a different field  
  
 elseif ( "submitted" == event.phase ) then  
 -- This event occurs when the user presses the "return" key (if available) on the onscreen keyboard  
  
 -- Hide keyboard  
 native.setKeyboardFocus( nil )  
 end  
  
end  

I added the listener to the text field.

myTextField = native.newTextField( 0, 0, display.contentWidth\*.6, 25, fieldHandler) [import]uid: 7559 topic_id: 1337 reply_id: 4164[/import]

It never worked in the past … I did not try it again with beta 6 yet. may do so tomorrow. [import]uid: 6928 topic_id: 1337 reply_id: 4167[/import]

Tom,

this doesn’t work in Beta 5
the text field is not removed

and if you replace myTextField.isVisible = not myTextField.isVisible
with myGroup.x=100, the text field doesn’t move even though it belongs to myGroup.

you can hide it by using

myTextField.isVisible=false or

myTextField.x=500

but it cannot be removed, and it behaves as if it doesn’t actually belong to the group.
the way it is right now, there’s no meaning into inserting a native text field in a group.

[import]uid: 6459 topic_id: 1337 reply_id: 4172[/import]

Okay, I was wrong. It turns out I was testing with a version of the SDK that fixed the “removal” issue. I was attempting to prove that the previous versions didn’t work and couldn’t. I guess that proves the upcoming fix DOES work.

I have verified that the test code does fail in beta 6 and works in the upcoming beta version. Stay tuned.

-Tom [import]uid: 7559 topic_id: 1337 reply_id: 4175[/import]

@tetu,

The fix will allow you to remove native.textField/textBox from the screen with object:selfRemove().

The Corona documentation states that the native objects do not obey the Corona display object hierarchy nor do they inherit display group properties (i.e. isVisible, x, y, and alpha). You still need to set the properties on the native objects directly. That part hasn’t changed.

When objects (native or otherwise) are created, they are part of the current stage, which is a group. Since the native objects don’t inherit any of the group properties, it doesn’t make sense to add them to another group. Generally they would be displayed temporary (i.e. to input some text) and then dismissed.

-Tom [import]uid: 7559 topic_id: 1337 reply_id: 4184[/import]

The following code doesn’t work :

choix_single = native.newTextField( 20, 60, 280, 30, fieldHandler )
choix_single:selfRemove()

I have the following error message : attempt to call method ‘selfRemove’ (a nil value)

What’s wrong with this code ?

Thanks in advance !

(nb : of course, I’ve made the fieldHandler listener in my textField)

[import]uid: 6149 topic_id: 1337 reply_id: 4529[/import]

I guess you are trying this on the simulator.

The simulator does not support “native.newTextField()” and the “replacement” table which is returned does not contain “removeSelf()”.

It seems like they want to program a stub for this functionality on the simulator and that is not finished yet.
You need to check if you are on the device and may use your own replacement function otherwise! [import]uid: 6928 topic_id: 1337 reply_id: 4530[/import]

Try choix_single:removeSelf()

That should work better. :slight_smile:

-Tom [import]uid: 7559 topic_id: 1337 reply_id: 4537[/import]