In this post I’m going to unravel some of the key points of saving datepicker & dropdown values into a collection, and then displaying them in a gallery.
I have a collection with details of trips, and so I needed a way to add more line items and have them saved in the collection before submitting the form.
Each of my line items has an arrival date and time, as well as a departure date and time.
Note: I do not have a datasource for this, as I will be using the collection to build a JSON string of items. So the collection itself is the destination for all this data.
I’ve handed the creation of new line items to a simple button.
Here’s the code behind the button
lineTripDescription: "Add your trip information here",
As you can see, I use the collect function to create the line items, adding them to my collection called “tripDetails”. You’ll notice that there are strings, and there’s a number for the trip cost. They are just values, remember that.
Now, for the patch function and explanation.
Firstly, I place the patch function on my save button icon. It is attached to the onSelect event/property.
So firstly, you can see that my ‘data source’ is set to the tripDetails collection. The ‘record’ to update is the line item, which uses the ThisItem variable. The important parts to notice are in the values section.
The date and time values need to be entered into the collection as values. i.e. strings. In order to output them as values, I wrapped them in the Value function.
So the datepicker field uses lineitemname.SelectedDate format &
the dropdown menus use lineitemname.Selected.Value format.
That’s not all… I checked my collection and it was indeed saving the values, but I wasn’t getting any output from the gallery items.
My hour and minute dropdowns were showing “00” on every save.
I’d forgotten to set the default values for those fields (or maybe I’d deleted them in my frenzy to fix things)
So select your field, then look on the right hand side at the properties pane and set the Default to the name of the field.
Hope this helps somebody.