Saving the previous state of a self.items data structure

Please see below for a sample application.

The app is taking user input from a selection of check boxes representing different events. If an event is selected and the user wants to add a schedule. Repeating panel rows are displayed for each event and a starting date date-picker component and an ending date date-picker component are displayed in each row.
what is a good way to store the dates selected to the event list? I also want the user to be able to add more events after they have selected some, and keep the date picker data for events that were previously selected.

https://anvil.works/build#clone:IHSUV57ON3RK7FDD=TOX3H5X7UZC3MWI4FCVJFH7K

In general, you can store data in the client by using the tag property of any component.

For example,

self.tag.my_event_list+=['some_event_label']

or,

self.my_nav_bar_link.tag.my_stored_string='my_string'

Any components can take arbitrary tags to store what you like.

The other option is using session data. If you search the forum for tags and/or session data, you will find many examples. Of course if you need to store persistent and/or large data, you would want to use DataTables.

Let me know if I have misunderstood the core question.

The behavior I am after is to update a client side events list with with the date-picker values for the start and end dates of that event. I also want the user to be able edit the the events list without losing the data already stored in the list.
The larger pattern I am trying to find is as follows:

  1. take some user input i.e strings, check-boxes, drop down fields, store those inputs in a list of dictionaries.

my_list = [{"input" : input1},{"input" : input2}]
  1. drive the forms repeating panels self.items with this list.

3)take further user information from the repeating panel components i.e. date-picker and store that information back to the list.
4) write all that information back to the database on some event i.e button_click

I realized i needed a my_global_list, i find the items that have been removed from my_list and remove them from my_global_list - representing what the user has deselected. then i find the items that are new on my_list and add them to my_global_list with placeholder valuers for any other user input fields

my_global_list = [{"input" : input1, "start date"  : "", "end date" :  ""},{"input" : input2, "start date"  : "", "end date" :  ""}]

I set self.repeating.items = my_global_list

Is my_list a strict subset of my_global_list?

no, my_list is rewritten every time the user inputs change. if the user deletes a previous input, then that input is deleted off my_global_list. If the user adds a new input then that input is added to my_global _list

So, as a result of the rewrite, is the data in my_list a strict subset of the data in my_global_list? Same dictionary keys and values?

I was looking for a way for you to maintain one list instead of two.

Trying to keep two things constantly in sync requires code, code that is sensitively dependent on the data layout and naming conventions. (And if it’s more than two things, it’s even worse.)

yes, i believe as a result of the rewrite my_list will be strict subset of my_global_list

Then you might be able to get away with using just my_global_list. If that’s possible, then all of the synchronization code goes away.

see here a sample app, I dont see how i could get the desired behavior without having two lists
https://anvil.works/build#clone:IHSUV57ON3RK7FDD=TOX3H5X7UZC3MWI4FCVJFH7K

What about something like this?

I think it’s cleaner…

https://anvil.works/build#clone:FHDHWNOLG26HKJ64=K5B6OVFVCI6IGL2YDPM35LWQ

1 Like