Developer Docs - Mobile Docs - Daily Challenge Entry
Displays a set of challenges for the individual to complete today.
M v3.0 C v12.5
This one is going to be a challenge to describe, but we'll get you up to speed on how to use it. This block allows you to build a visual interface to provide challenges to your people. These challenges span multiple days and comprise one or more individual challenge items on each day. An example might make more sense of what we are talking about.
Let's suppose you want to have a 7 day "Get to Know God" challenge. Each day they are prompted to complete two tasks: Prayer and Bible reading. Each day would give different instructions about what to pray for and what verses to read. When they first land on the page hosting this block they will see the challenge items for day 1. After they tick those off they might see a "way to go" type message. Then the next day when they return they will see the items for day 2, and so on. Once they finish day 7 and come back the next day they start on day 1 again.
Lava Reference
When your lava template is parsed, you will get a number of merge fields to help you render the daily challenge. There is some sequence of operations you will need to be aware of.
First, you will probably want to check if the CompletedChallenge merge field is not null. If it contains a value then that means the user just finished the final challenge item for a day. In this case, you likely want to display some kind of "well done" message, or possibly switch to a read-only view that removes the check-boxes - since trying to uncheck an item from a fully completed day is not allowed. In this case, the Challenge merge field may contain either the same object as the CompletedChallenge or it may contain what the system thinks is the "next" daily challenge, depending on the situation. But generally you probably don't want to just display whatever is in the Challenge at this point.
Secondly, if the MissedDates merge field contains any values then those should be displayed to the user and must be filled in before you display the challenge in the "Challenge" merge field. Otherwise, they will start a new challenge. Also, the MissedDates must be filled in sequentially. Meaning, if they missed two dates they need to fill in the challenge for the first date and then the second date, otherwise it will also break the challenge and start them over. The default template displays just the first date of the array.
You can have both a CompletedChallenge value as well as items in the MissedDates array. For example, say there are two missed dates and you have them continue and fill out the first missed date. Upon completion, your CompletedChallenge merge field will contain the first missed date challenge they just completed and your MissedDates array will now have a single item for the second day they had missed.
Merge Fields
Object Structure
ChallengeState
DailyChallenge
This object contains all the details about a single day of a challenge.
ChallengeItem
This object contains the information about a single checkbox item that will be displayed for the user to complete.
ChallengeItemValue
Contains the user-supplied information about a single challenge item. Meaning, if it has been completed and any custom user value that was entered.
XAML Bindings
So your lava template will set up the initial XAML content to paint the page. But how do you link user actions (like tapping a checkbox) back so it actually does something? There are some special bindings available to you:
Okay, so those are the XAML bindings available. But examples certainly make more sense than just the description. For a moment, lets imagine that all we are going to display is a checkbox and the name of the item to be completed. So we will loop through the Challenge.ChallengeItems array and render out a horizontal stacklayout to contain our checkbox and then the label.
{% for item in Challenge.ChallengeItems %}
{% endfor %}
Most of that should look pretty normal to you. We have a bit of a mix between lava and bindings. In some places we are using lava to display a value (for example, the Label text). In others, you will notice we are using binding values. The binding value means it will actually persist the change in value. If we had used a normal lava "if" statement then it wouldn't automatically update or track the change in value.
But, that binding syntax is probably not what you normally see, so let's break it down. There are two parts to the binding, first is the path and then the converter. Let's take a look at that path first.
Challenge.ItemValues[{{ forloop.index0 }}].IsComplete
{Rock:BooleanValueConverter True=check-circle, False=circle}
You might wonder why we didn't just use an actual checkbox. The reason is that the checkbox doesn't have a Command. And when you bind the value of the checkbox to the IsComplete property it won't properly pick up the fact that we might reject the change in value if it isn't allowed.
Setup
So how do you set up these challenges? You are going to use a Content Channel to do that. You will also need to setup 2 Content Channel Types (if you set up multiple challenges you can re-use these channel types).
Content Channel Types
The first content channel type will hold the challenges that you are going to set up, in this case we are talking about your 7-day "Get to Know God" challenge. To create a general use Content Channel Type for these challenges. Create a new Content Channel Type with the following settings:
Next, create a second Content Channel Type that will hold the individual items to be completed each day.
The item attribute allows you to specify that the challenge item should have a (required) input field. You can also define other item attributes and these will be included in the Lava so you can better customize how things are displayed.
Content Channels
First, we are going to create the content channel that will hold the individual challenge items to be completed each day.
Now you need to create a Content Channel for the actual 7-day challenge.
You can also add Item Attributes to this channel. These will apply to the individual days (Day 1, Day 2, etc) and be made available to you in Lava. This allows you to customize each day if you want.
Day Items
It may seem obvious, but you need to create a Content Channel Item inside your "Get to Know God" channel for each day. To keep things simple, just create 7 items titled "Day 1", "Day 2", and so on up to "Day 7". If you get things out of order, you can use manual sorting to put things in the proper order. That order is used to determine the order of the days, not the title.
All you really need is the Title, but you can enter some XAML in the Content that will be displayed at the top of the page when viewing that day's challenges.
Challenge Items
Go into "Day 1" and create a new child item.
Then add a second item to be the challenge item for reading the bible.
So we now have two items that will be displayed for "Day 1". The first is a checkbox with the title "Pray for 15 minutes" and no additional content. The second item will be a checkbox with the title "Read the Bible" and then below that it will display the verses that they are supposed to read.
To complete this you would do the same for "Day 2" through "Day 7". And obviously you can use different verse references. You can even have them in different order or additional items to be completed on certain days.
The default lava template expects you to use XAML inside the Content fields for both the Day content channel items and the individual challenge item content channel items. If you try to use just a plain text string it will throw a rendering error.
Styling
Since this is a XAML template there is no styling X-Ray