Popovers updating a form

Hi @stucork

Wonderful invention! However, I have an issue that I just cannot seem to resolve. I have a textbox. Depending on the text in that box when it loses focus, I trigger a popover from a link below that textbox. I check the text in the box when it loses focus, send some arguments to another function which triggers the popover.

I use a separate form when i trigger the popover, a form with an announce label and buttons etc. But try as I might, this form is ALWAYS the same as when the popover was first triggered.

Example:
In the text box is some text “Something” When it loses focus I want the popover form to say “Looks like a new item”, with buttons “Yes” and “No”

I therefore initiate and pass the appropriate arguments to the form. Then I activate the popover: my_link.popover(my_form,placement=“Top”,etc) and: my_link.pop(‘show’)

All good.

Now, I change the text box text to “” (blank). When it loses focus I want the popover form to say “You must type something”, with button “OK”.

I therefore initiate and pass the different arguments to the form. Then I activate the popover: my_link.popover(my_form,placement=“Top”,etc) and: my_link.pop(‘show’)

But even though the form has received the new, different arguments, in the popover it is still the same as the first case, with “Looks like a new item”, with buttons “Yes” and “No”.

I just cannot seem to update the form once it’s been given to that link’s popover. I’ve tried to dispose of the popover when the OK or NO button in the form is pressed. Get an error (unrecognised behaviour: dispose.

I’ve tried refreshing data bindings. Nothing different happens
I’ve tried my_link.pop(‘update’), then my_link.pop(‘show’). Nothing different happens.

I guess it comes down to this question:
How do I update the popover’s form or content on a specific button or link before i show it again?

Thanks in advance!

hi @bruce.fraserb,

Can you put together a clone link. It’ll be much easier to dig into what you’re trying to do and what’s not working.

Just reading the explanation I’m not able to tell where exactly the problem lies.

https://anvil.works/build#clone:2DTXAY6UJPZTM4C6=SDO7E6OKVPB4VHKV5VAM4QZW

Hello again @stucork

To simplify I’ve made a new little app, but I’ve replicated the problem. Form2 still doesn’t update on subsequent firing of the popover.

So I would either destroy your popover on the textbox focus event:

  def text_box_focus(self, **event_args):
    """This method is called when the TextBox gets focus"""
    self.pop_link.pop('destroy')

or
Keep a reference to the pop_form and update its contents

  def __init__(self, **properties):
    # Set Form properties and Data Bindings.
    self.init_components(**properties)
    self.pop_form = Form2('',[False,False,True])
    self.pop_link.popover(self.pop_form,
                          trigger='manual',
                          placement='bottom',
                          max_width=400)

  def pop_handle(self,which,**event_args):
    if which == 1:
      msg = 'Would you like to save ' + self.text_box.text + '?'
      butt = [True,True,False]
      print(1)
    else:
      msg = 'Please enter some text'
      butt = [False,False,True]
      print(2)
    self.pop_form.update(msg, butt) # to write - basically the __init__ method
    self.pop_link.pop('show')


1 Like

Beautiful. Thanks so much.

For the record I used:

def pop_handle(self,which,**event_args):
if which == 1:
  msg = 'Would you like to save ' + self.text_box.text + '?'
  butt = [True,True,False]
  print(1)
else:
  msg = 'Please enter some text'
  butt = [False,False,True]
  print(2)
pop_form = Form2(msg,butt)
self.pop_link.pop('destroy')
sleep(0.2)
self.pop_link.popover(pop_form,trigger='manual',placement='bottom',max_width=400)
self.pop_link.pop('show')

Basically just wrote the destroy line in, got the app to wait a bit, then start again.