Your line
if nombreinput ~= “” then
correct line
if nombreinput.text ~= “” then
Your line
if nombreinput ~= “” then
correct line
if nombreinput.text ~= “” then
Nope I already try that too, even creating a local var and asign the variable to the nombreinput.text but the same. Even debugging with adb it detect only the empty, in both cases.
I read other post and in a reply from corona staff, they said the workaround of the local var but i test that too and is wrong.
I’m working on Android btw.
Well I use text objects all the time on Android and I have not seen this issue before. The fact is that in your code nombreinput is a text field object so you can not check it as a string. The text field object has a property text that holds the current text. Before you check the text property print it out so you can see in the terminal windows what is returning.
print(nombreinput.text)
Do you have some working example? because after an update on my code still not working:
-- Create our Text Field local nombreinput = native.newTextField(centerX-131, \_H-40, 250, 24 ) nombreinput.align = "center" nombreinput.size = 18 nombreinput:setTextColor( 1, 0.5, 0 ) nombreinput.text = "Introducir Nombre..." nombreinput.inputType = "default" function checkcampos() if nombreinput.text ~= "" then print ("the nombreinput field is ", nombreinput.text) else print ("the nombreinput field is ", nombreinput.text) end end
What does it print in the terminal window?
Also try adding an input event listener.
function inputEvent(event)
print(event.text)
print(event.target.text)
end
nombreinput:addEventListener(“userInput”, inputEvent)
The terminal window don’t get any value because in the newtextfield is not accesible on the simulator (stay gray):
the nombreinput field is
the nombreinput field is
And when i write something (fffffrff) on the field (on the phone) the adb log says:
I/Corona (25944): the nombreinput field is fffffrff
I/Corona (25944): the nombreinput field is fffffrff
I/Corona (25944): the nombreinput field is fffffrff
I/Corona (25944): the nombreinput field is fffffrff
But my idea is that when a user leave the field empty a popup shows saying (you cannot send because field X is empty) and to do that i have to get the current value of the field, the problem is that there’s no difference once you are on android (in this case), the newtextfield always return empty.
Ah right you are on windows. Well that would be the reason why it doesn’t work. Run it on device and check in logcat what gets printed (filter: corona).
Validate button without text on nombreinput:
I/Corona (25944): the nombreinput field is
I/Corona (25944): the nombreinput field is
I/Corona (25944): the nombreinput field is
I/Corona (25944): the nombreinput field is
I/Corona (25944): the nombreinput field is
I/Corona (25944): the nombreinput field is
Validate button with text ( lllll ) on nombreinput:
I/Corona (25944): the nombreinput field is lllll
I/Corona (25944): the nombreinput field is lllll
I/Corona (25944): the nombreinput field is lllll
I/Corona (25944): the nombreinput field is lllll
Till then all is ok (in theory) but know… wait emmm I see what you trying to tellme with the (The text field object has a property text that holds the current text.) i have to use another if inside right?
I’m not sure what you are trying to do. textField.text is the text that is currently displayed in it. Is that not what you want?
It’s very ease, im trying to show a native message (hey! the nombrefield is empty!), when the user leave the nombreinput field empty. When is not, shows another native message (hey! you have completed the nombrefield!) The problem is that when the field is empty the app shows “hey! you have completed the nombrefield!” and there is no characters inside. Is like he have a blank space but is not.
Well your logcat output looks right so I don’t know what the issue is. Are you saying that when you have this in logcat:
I/Corona (25944): the nombreinput field is
Your app still says that it’s not empty?
Try outputting this to see if there are spaces in the text box:
print (“the nombreinput field is '”…nombreinput.text…"’")
now if it’s empty you should get
the nombreinput field is ‘’
if it’s not then it will be
the nombreinput field is ’ ’
Yes! that’s exactly my problem!
Gonna try what you say.
actualy try this and post adb log results:
function checkcampos() print ("the nombreinput field is '"..nombreinput.text.."'") if nombreinput.text ~= "" then print("not empty") else print("empty") end end
adb log
I/Corona (12251): the nombreinput field is ‘’
I/Corona (12251): empty
I/Corona (12251): the nombreinput field is ‘’
I/Corona (12251): empty
I/Corona (12251): the nombreinput field is ‘’
I/Corona (12251): empty
after insert some text:
I/Corona (12251): the nombreinput field is ‘llllll’
I/Corona (12251): not empty
I/Corona (12251): the nombreinput field is ‘llllll’
I/Corona (12251): not empty
I/Corona (12251): the nombreinput field is ‘llllll’
I/Corona (12251): not empty
I don’t see the problem. It’s working as it should. Now where the print(“empty”) is put your warning.
oh boy… i was putting the message in the wrong place, when was not empty i put empty and vice versa :p
Thanks for all
Kind regards.
Ah yes the infamous reverse if bug :).
You’re welcome.