I have a Repeating Panel that is creating instances of Forms based on a template. Once the Form has been instantiated I want to be able to access the properties of elements on that Form (e.g. foreground color of the Text in a Text Area).
Once instantiated, I don’t know how the instance of the Form is referenced.
How do I access the properties of the elements on the instantiated Form?
If you are asking how to access the parent of a repeating panel template, or in general, how to access another form while in the template, there are many posts on the forum about this.
Try searching the forum for “accessing parent form from repeating panel” or something like that.
Or, you may be asking about the repeating form’s template itself. The code view (and designer view) for that form should be accessible just as it is with any other form (by clicking in the IDE where the template form is created, or double clicking the outer repeating panel).
Thanks for the quick response!
Actually that isn’t quite it, in fact it is almost the inverse.
The application runs and the RepeatingPanel.items gets populated with a Dictionary.
The information in that Dictionary is then instantiated into the Form objects that the Repeating Panel creates from the RepeatingPanelTemplate.
What I want to do is programmatically access a property on the instantiated Form.
I don’t want to change the content on the instantiated Form which is coming from the Dictionary (that could be done via modifying the contents of the Dictionary in the RepeatingPanel.items.
Specifically I want to modify a textbox property (e.g. foreground) of a single instantiated form so that the text in that textbox on just that instantiated Form (not on the other Forms instantiated from the same template) stands out.
Okay, so it seems that you are pointing to one of the repeating panel’s children (defined in the template form).
If you are asking how to change only one of the children (an instance) and not all, then you could check some data in the init of the template form (using self['item'], and make changes there.
# in the template's init
if self.item['your_key']>'some_value':
self.my_text_box.foreground='red'
PS) when sharing a clone, you never need to share your actual app. Rather, just a simple example app that demonstrates the issue. Screenshots are fine here though I think.
Again, thank you very much for being so responsive.
Each of the rows in the graphic are created by the repeating panel from the same template. My use case is that I want to access a specific element (the date textbox) in only one of the rows (a unique Form instance). In this case, I want to modify the date textbox of the 4th row only. If I modify the template, each of the instances of the Form (each row) will get the same formatting.
I am trying to write logic to conditionally format the date textbox based on it’s contents, but I don’t have the information at hand when I instantiate the row, so I am trying to access the properties of the elements after the fact when I have the other data I need to ascertain if the condition is met or not.
I assume you will get the information when a particular event occurs (date change, text box change, etc).
Therefore, when the event occurs, a function in the template row is called (if you have set one up - search “events” in the docs if that is not familiar territory).
Anyway, it seems that you will need to associate some extra data to items when you make the repeating panel so that at some later time, you can determine which row you are on.
You can store values like this:
# in template's init
self.tag.my_row_number=self.item['a_row_number']
Then later in the callback function on that same form:
Thanks for the information, it seems that the behavior of the RepeatingPanel is different than I had envisioned. I assumed that the process of instantiating a usage of the template would produce a referenceable Form object which would have its own children (textboxes, etc…) that would have their own properties that could be called by other parts of the application.
From your explanation I see that the concept of instantiation is dynamic, in that no persistent object is created, but instead the RepeatingPanel is managing the presentation of the data in its .items Dictionary in the main Form in which the RepeatingPanel lives. Thus you can’t modify the properties of elements on an “instance” because it doesn’t exist as a standalone object.
I believe you’ve got the correct overall thinking. Repeating panels are used when you want to repeat n sets of elements according to some template/layout. Usually the data are being pulled as rows from a datatable and are bound to the repeating panel.
Now, as mentioned, you can bind data to the repeating panel and that will let you distinguish a particular row. Also, if you use self.repeating_panel.get_components() you will indeed get a list of forms objects that you can manipulate (e.g., perhaps you want the 4th one).
If you want a table-like arrangement that is fixed at a certain number of rows, and you want to treat the rows the separately, you can manually create that layout with other components (e.g., flow panels, linear panels, column panels). You can also create a form yourself, import it into another form, and repeat it (as if it was a template form). All such things come with trade offs. I suspect you will still want a repeating panel though based on your image above.