What additional steps do I need to take set the date-picker's initial-value to the user's birthday using the viv.self library? Is this the best place to handle this? Currently I am setting the default to 30 Years Prior.
render {
date-picker {
// Default Date -30 Years (viv.self Birthday Option)
initial-value ("subtractDuration(now().date, 'P30Y')")
restrictions {
// allow selection 80 Years Ago
min-allowed ("subtractDuration(now().date, 'P80Y')")
// to allow selection 18 Years Ago
max-allowed ("subtractDuration(now().date, 'P18Y')")
}
}
}
- You can use a
match-pattern
to achieve this.
- Birthday is a part of the viv.contact library but is not available in the viv.self library.
In your Action, create an additional attribute of type time.Date
(or a concept with role-of
of time.Date
) to hold the Birthday.
Heres how the code would look like.
action (GetBirthDate) {
type(Constructor)
description (Collect the date selected by a user)
collect {
input (usersBirthday) {
type (BirthDate)
min (Required) max (One)
default-init {
intent {
// TO-DO Get the birthday with an intent
}
}
}
// This input will hold the value entered by the user
computed-input (birthDate) {
type (BirthDate)
min (Required) max (One)
compute {
intent {
goal: BirthDate
}
}
}
} output (BirthDate)
}
The BirthDate concept used in the code above looks like this
structure (BirthDate) {
description (__DESCRIPTION__)
role-of (time.Date)
}
Your input-view will look like this. This defines a match-pattern
that is invoked whenever we need an input view for BirthDate and that BirthDate is functioning as an input back to the action.
Checkout match patterns here: https://bixbydevelopers.com/dev/docs/dev-guide/developers/customizing-plan.match-patterns
input-view {
match: BirthDate (this) {
to-input {
GetBirthDate (action)
}
}
render {
date-picker {
initial-value (action.usersBirthday)
restrictions {
// allow selection 80 Years Ago
min-allowed ("subtractDuration(now().date, 'P80Y')")
// to allow selection 18 Years Ago
max-allowed ("subtractDuration(now().date, 'P18Y')")
}
}
}
}