Clearing textfield.text

I’m trying to setup a textfield to allow the user to input some data, this all works just as I would expect, except once the data has been added by an “Add Button” how do I clear the textfield.text so it will be blank for the next input of data?

I use this for cleaning text field

self.getSibling("Label").props.text = ""

OK, I will try that. How would you test to make sure textfield is NOT Blank.

Like this ?

empty = self.getSibling("TextField").props.text
	if empty == "":
	       self.getSibling("TextField").props.text= "YES"
	else:
	      self.getSibling("TextField").props.text ="NO"

Thank You!

self.getSibling("TextField").props.text == ""

Only tests for empty Strings.

# This following code also checks to make sure that the property value is not None.
# In the previous snippets in this thread, a None value would have evaluated as text being present.
displayed_text = self.getSibling('TextField').props.text
if displayed_text and len(displayed_text) > 0:
    # There IS text
1 Like

value = u’’
event.source.parent.getComponent(‘Text Field’).text = value

Try this to your ADD BUTTON and it works for me

Very well done and complete. Thank you.

Or just if displayed_text:, because an empty string is already 'falsey' in Python :slight_smile: