Required Text Input (eg. Input must not be blank)

Hi guys,

Is there a simple way to add a validation on a native.newTextField() input such that the input must not be blank?

I know this is a basic input validation but I am not familiar as to how, in Corona (lua) shall we do this the easiest way.  

cheers,

Santi

https://docs.coronalabs.com/api/library/native/newTextField.html#examples

You can check the text object in the “ended” phase.

Hi bgmadclown,

Thanks for your feedback. Yes I had gone through those documentations.  What I actually need to see, is how you construct a code logic, to repeat the process of entering the text until it satisfies the condition.

something like…

Repeat

   …  [input text here]

   …

Until myText.text != nil or myText.text != “” 

I did similar to that, but it crashes my code.  It seems to be calling the listener repeatedly, it hangs and eventually it crashes the simulator.  

local function textListener( event ) if ( event.phase == "began" ) then elseif ( event.phase == "ended" or event.phase == "submitted" ) then if (#event.text \<= 0) then print "error" end elseif ( event.phase == "editing" ) then end end

Is it what you are after?

Brilliant!  Thanks bgmadclown.  That works!

I wasn’t aware that if you add that condition, it sort of keep the input going!!    

Cheers!

Santi

https://docs.coronalabs.com/api/library/native/newTextField.html#examples

You can check the text object in the “ended” phase.

Hi bgmadclown,

Thanks for your feedback. Yes I had gone through those documentations.  What I actually need to see, is how you construct a code logic, to repeat the process of entering the text until it satisfies the condition.

something like…

Repeat

   …  [input text here]

   …

Until myText.text != nil or myText.text != “” 

I did similar to that, but it crashes my code.  It seems to be calling the listener repeatedly, it hangs and eventually it crashes the simulator.  

local function textListener( event ) if ( event.phase == "began" ) then elseif ( event.phase == "ended" or event.phase == "submitted" ) then if (#event.text \<= 0) then print "error" end elseif ( event.phase == "editing" ) then end end

Is it what you are after?

Brilliant!  Thanks bgmadclown.  That works!

I wasn’t aware that if you add that condition, it sort of keep the input going!!    

Cheers!

Santi