我想收集用于“评估”操作的地址输入。理想情况下,行为应如下所示:
1) Evaluate is initiated
2) a default address is pulled from user profile,
user is asked if they would like to use this address
3) if no default address or user does not want to use it,
prompt user for an address
4) Evaluate action runs with either default address or custom input address
我正在考虑做的是添加2个可能会返回geo.Address对象,ReturnSelfAddress和GetCustomAddress的构造函数动作。 ReturnSelfAddress将从自助图书馆胶囊中收集一个地址,GetCustomAddress会提示用户输入地址作为geo.UnstructuredAddress并将其转换为常规的geo.Address。
“评估”操作的输入是:
input (address) {
type (geo.Address)
min (Required)
max (One)
default-init {
intent {
goal: ReturnSelfAddress
}
}
}
然后,我将具有一个确认视图,该视图将确认ReturnSelfAddress以让用户根据需要选择该视图。如果ReturnSelfAddress失败,则Evaluate仍将查找geo.Address输入。我将有一个匹配geo.Address概念的输入视图,并提示用户输入geo.UnstructuredAddress。这样的事情(不确定这是否100%正确):
input-view {
match: geo.Address(this)
message ("What is your street address?")
render{
form {
elements {
text-input {
id (address)
label("Address")
required (true)
type (geo.UnstructuredAddress)
}
}
on-submit {
goal: GetCustomAddress
value: viv.core.FormElement(address)
}
}
}
}
或者,如果用户拒绝默认设置,那么我将有一个GetCustomAddress的中止目标,它将提示用户:
on-abort {
intent {
goal: GetCustomAddress
}
}
这似乎很复杂,我在质疑是否存在我可能会缺少的功能,它将帮助我获得所需的行为。所以我想我有2个问题:
1)在我深入这个兔子洞之前,这个想法行得通吗?
2)是否有更好的方法来获得“尝试默认设置,如果没有尝试或用户拒绝,则提示输入”的期望行为?
答案 0 :(得分:1)
您可以尝试确认视图,但这是您发现有用的一种简单方法。
input (email) {
type (TypeTextEmail)
min (Required) max (One)
default-init {
intent {
goal: FetchEmailFromName
value: $expr(name)
}
}
prompt-behavior (AlwaysElicitation)
}
input-view {
match: TypeTextEmail(this)
render {
form {
elements {
text-input {
id (this)
type (TypeTextEmail)
label ("Email:")
max-length (50)
value ("#{value(this)}")
}
}
on-submit {
goal: TypeTextEmail
value: viv.core.FormElement(this)
}
}
}
}
有关确认视图,请参阅Github上的example.shirt