Is it possible to access a repeating panel's methods from the parent form?

I have a form with a few singular fields and a repeating panel. I have validation methods for the regular fields, and I can trigger them on update, on lose focus and when hitting the submit button. I have validation methods for the fields within the repeating panel too, and although I can trigger them in events within the repeating panel, I can’t seem to be able to trigger them from the main form (e.g. when the main form’s submit button is pressed).

Simple example:

class MainForm(MainFormTemplate):
  ...

  def validate_foo(self, **event_args):
    if len(self.foo.text) == '':
      self.foo.border = '2px solid red'
      return False
    else:
      self.foo.border = ''
      return True

and

class RepeatingPanel(RepeatingPanelTemplate):
  ...

  def validate_bar(self, **event_args):
    if len(self.bar.text) == '':
      self.bar.border = '2px solid red'
      return False
    else:
      self.bar.border = ''
      return True

I want to be able to call the validate_bar method from the main form, but as far as I can tell the instance of RepeatingPanel isn’t accessible from MainForm.

I want to do something like this:

class MainForm(MainFormTemplate):
    ...

    def on_submit(self, **event_args):
      valid = all([
        self.validate_foo(),
        all(bar.validate_bar() for bar in self.bars)
      ])
      if valid:
        alert("OK")
      else:
        alert("Errors")
        
1 Like

Hi @ben2 and welcome to the forum.

If I understand correctly, you could use the repeating panel’s raise_event_on_children method.

com-video-to-gif%20(7)

There is a clone in that post you can click on to copy the app. You will see that on the main form there is a button. When it is clicked, an event is triggered on each row (i.e., template) in the repeating panel.

This is functionally equivalent to looping through the repeating panel’s children, and calling a method on each child. For example, if your template has a method foo, you could call it from the parent form as follows:

# in parent form
for c in self.repeating_panel.get_components():
  c.foo()

Does this work for you?

2 Likes

Awesome. Thanks for the quick response - exactly what I was looking for!