TextBox lost focus event handler in Repeating panel

Hi,

I have a RepeatingPanel, within its RowTemplate are two pairs of a Link and a TextBox. My intention is to display TextBox when a user clicks the Link (and hide the Link), and to redisplay the Link and hide TextBox when TextBox looses the focus.

The event handlers are:

  def link_value_click(self, **event_args):
    """This method is called when the link is clicked"""
    self.link_value.visible = False
    self.text_box_value.visible = True

  def text_box_value_lost_focus(self, **event_args):
    """This method is called when the TextBox loses focus"""
    self.refresh_data_bindings()
    self.text_box_value.visible = False
    self.link_value.visible = True

Basically it works fine, except that the lost focus handler is sporadically not being run - sometimes it does work, sometimes not, for the same element. Might be that the “lost focus” is picky in regard to what has been clicked or the way for the focus to get lost (i.e. tab)?

Thanks, Tomaz

It could be that the two events are in a race and click wins…

Does it only happen when your user goes from being inside the textbox to then immediately clicking the link?

breaking it down…

  1. your user is inside the textbox and then…
  2. …your user clicks the link
  3. … the link click behaviour may win the race before textbox has a chance to raise lost_focus

Ah, I noticed that for TextBox to have a focus means that the cursor has to blink in it, so it has to be clicked twice - fistly the link and then the text box. I remedied the situation with additional call to TextBox’s focus() method:

  def link_value_click(self, **event_args):
    """This method is called when the link is clicked"""
    self.link_value.visible = False
    self.text_box_value.visible = True
    self.text_box_value.focus()

Thanks, @stucork for pointing me to a careful inspection, what’s really going on.

Tomaz

3 Likes