Repeating panel to collect new information?

I’ve created a panel with several fields. I want to use this to collect new information that isn’t already in the database. However even though I have set it up properly, when I run the app nothing appears: (screenshot https://imgur.com/a/RWIPs)

Is there any way to tell the repeating panel how many times I want it to appear in spite of there not being any existing data to show?

Not that I’m aware, unless you want to put some dummy data in there.

You could try creating an initial array of blank spaces - not tried it myself but it might work. Eg :

data=[
    {"dummy":" "},
    {"dummy":" "}
] 

Then add it in you line item form for the panel. Worth a go. If there is data you could use that to pad it out to the required number of lines.

This is exactly the right way to do it. In fact, I would probably create one or more named dummy objects so that I can easily refer to them later. Something like this, perhaps:

  def __init__(self, **properties):
    self.init_components(**properties)
  
    # When the form is created, populate the RepeatingPanel
    self.data = [ ...your actual data... ]
    self.new_item = {"foo": "", "bar": ""}
  
    self.repeating_panel_1.items = self.data + [self.new_item]
  
  def save_new_item_click (self, **event_args):
    # When the "Save new item" button is clicked, 
    # do something to store the new data, and refresh the list.
  
    # May want to actually save self.new_item somewhere.
    # For now, just add it to self.data.
    self.data += [self.new_item]
  
    # Create a new blank item for the end of the list, and 
    # repopulate the RepeatingPanel.
    self.new_item = {"foo": "", "bar": ""}
    self.repeating_panel_1.items = self.data + [self.new_item]      

Hope that helps!

Thanks. That does help! I didn’t realize that the iterations are controlled by the ‘items’ property.

For my purposes, I can just instantiate it with this:

self.repeating_panel_1.items = range(10)

And call it with this:

for row in self.repeating_panel_1.get_components():
  print(row.sku.text)
  print(row.image.text)
  print(row.type.text)
2 Likes

so curious here if I’m populating my repeating table from a database object on load is there a easy way to refresh this after say someone adds a feeding record or something in my button call? Refresh data bindings doesn’t seem to be doing the trick and it only loads the updates to the feed table after I refresh the page.

Let me know if you need more context on this.

The RepeatingPanel repopulates itself each time its items property is set. So if you set it again (even to the same value!), it will rebuild its contents. (Calling self.refresh_data_bindings() only refreshes the data bindings defined on this form; it doesn’t do anything global. Read this post about data bindings for more info.)

If you’re triggering this from inside the RepeatingPanel (eg in a row of your table), you’ll need cooperation from the form that contains the RepeatingPanel. A good way to do this is to raise an event on the RepeatingPanel (which is self.parent if self is a form in the RepeatingPanel), then catch it in the containing form. So, in the template form, you do:

self.parent.raise_event('x-refresh-list')

…and in the form that contains the RepeatingPanel, you do:

def __init__(self, **properties):
  self.init_components(**properties)

  self.repeating_panel_1.set_event_handler('x-refresh-list', self.reload)

def reload(self, **event_args):
  self.repeating_panel_1.items = # ..whatever...

5 Likes

I’m still a little confused on this cause when I built this it errors about NoneType on the self.raise_event part in the template form so any clarification you can share there?

Thanks

so all I actually had to do was in my add feed record button I just called the reload function I used there and that does the trick :slight_smile:

So how might I do this when I have a delete button for example in my template and not in the full page so it doesn’t have the reload option. I tried importing the reload function from my page but then it just complains about reload taking arg’s even though its not setup to.

Any idea how to refresh a repeating panel after a button in that repeating panel template is clicked to say delete that record which works but it doesn’t reload the repeating panel and show that it is gone.

Thanks

looks like I had to do this:

get_open_form().content_panel.clear()
    get_open_form().content_panel.add_component(Excretion())

which just forces it to reload the page in the material UI dashboard setup basically.