Changing a TextField.isSecure to true at runtime

I’m doing a simple login form for the app I’m working on. The username and password textfield have a placeholder text that clears out when the user interacts with the text field. Here’s the code that do the clear:

scene.clearOnFocus = function(e) if (e.phase == "began") then if (e.target.text == e.target.hintText) then e.target.text = "" if (e.target.isPassword) then e.target.isSecure = true end end elseif (e.phase == "editing") then elseif (e.phase == "ended") then if (e.target.text == "") then e.target.isSecure = false e.target.text = e.target.hintText end end end

The logic here is that if the field have a variable isPassword that is true then when the clearing happens the field switch to a secured text field. But what is happening is that the field gets uneditable and the text never gets cleared out. If I assign isSecure to true from the begging it works but I want the placeholder text to show. What am I doing wrong?