Perspective text field lose focus on enter press

I am trying to make a text field lose focus after the enter key is pressed.

I am trying to use blur(), but it does not seem to work. Also related is setting the text property to empty ("") at the end does not work either, but I think that is because the text field still has focus.

> def runAction(self, event):
> 	"""
> 	Method that will run whenever the selected event fires.
> 
> 	Arguments:
> 		self: A reference to the component that is invoking this function.
> 		event: Events fired by the relevant keyboard interaction.
> 			altKey (bool): True if the 'alt' key was held down when the event
> 			               was fired.
> 			charCode (int | float): Deprecated.
> 			ctrlKey (bool): True if the 'ctrl' key was held down when the event
> 			                was fired.
> 			key (str): The value of the key interacted with in this event.
> 			keyCode (int | float): Deprecated.
> 			locale (str): The locale of the keyboard in use on the device. May
> 			              be blank.
> 			location (int | float): The location of the key interacted with on
> 			                        the keyboard.
> 			metaKey (bool): True if the 'meta' key was held down when the event
> 			                was fired.
> 			repeat (bool): True if the key is being held down such that it
> 			               automatically repeats.
> 			shiftKey (bool): True if the 'shift' key was held down when the
> 			                 event was fired.
> 			which (int | float): Deprecated.
> 	"""
> 	if(event.key == "Enter"):
> 		system.perspective.sendMessage("userResponse", payload=self.props.text, scope="page")
> 		
> 		self.blur()
> 		
> 		self.props.text = ""

Did you ever have any luck getting the text field to lose focus? Trying to do something similar

This may be of help to you: https://docs.inductiveautomation.com/display/DOC80/Perspective+Component+Methods#PerspectiveComponentMethods-RequestingFocus

You could use another component to take focus away from the component you’re trying to lose it from.

1 Like

Thanks, figured it out!