Text Field focus shows old value after clearing

Hi everyone,

I have a Text Field in Perspective that I want to focus when a button is clicked. On the button click, I call a handler that is associated with the Text Field. Inside that handler, I use:

self.focus()

The field does receive focus correctly, but the problem is that it still shows the previous value.

on button click

def runAction(self, event):
		
	self.getSibling("txt_user").props.text=""	
	system.perspective.sendMessage("focustxt_user", scope="page")

Has anyone run into this issue before? How can I reliably clear the text box and set focus to it when clicking the button?

I'd start by moving the text deletion into the message handler. That will get rid of all the getSibling syntax which breaks when you move components in and out of containers. (It's one of the benefits of using message handlers in the first place.)

I suspect that scope = 'view' would be adequate too.

Most likely, the text field is set to reject updates while editing (focused). Assignments to Perspective properties from scripts are not synchronous, so the focus might be reaching the field before the assignment.

(I probably wouldn't use a message if you have a reference to the component--you can use .focus() on that reference.)

Hi,

Fist thanks for helping.
i have used .focus() as you said but it did not effect any.

def runAction(self, event):
	
		
	self.getSibling("txt_user").props.text=""	
	self.getSibling("txt_user").focus()

Hi,
i have changed but still same.

system.perspective.sendMessage("focustxt_user", scope="view")

Duplicate the view, strip out everything except the text field and the button. In Project Browser, right-click, Copy JSON, and paste the code here. Wiki - how to post code on this forum.

Did you set rejectUpdatesWhileFocused to false?

1 Like

Hi,
Thanks a lot. It was set true i just set false and its working…

Thanks agian.