Bixby: How do I set an initial-value to self BirthdayInfo in a date-picker within a input-view?

本小妞迷上赌 提交于 2019-12-11 06:06:59

问题


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')")
  }
}

}


回答1:


  1. You can use a match-pattern to achieve this.
  2. 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')")
      }
    }
  }
}


来源:https://stackoverflow.com/questions/54892807/bixby-how-do-i-set-an-initial-value-to-self-birthdayinfo-in-a-date-picker-withi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!