sherpal/LaminarSAPUI5Bindings

DatePicker - am I using it right?

Closed this issue · 2 comments

I'm trying to use the datepicker.

    val strValue = Var[String]("")
    div(
      DatePicker(
        _ => onChange.mapToValue --> strValue,
      ) ,
      child.text <-- strValue.signal.map(x => s"Debug : $x")
)

I was expecting the .mapToValue call, to behave more or less like the input component. In this case, I can't seem to extract the value on change. Is there something obviously wrong with the above?

The problem is (I think) that the date picker does not have a value directly. This is one example from my own private repo:

DatePicker(
  _.formatPattern := "yyyy-MM-dd",
  _.value <-- babyFormVar.signal.map(_.dateOfBirth).map(localDateToString),
  _.events.onInput
    .map(_.detail)
    .filter(_.valid)
    .map(_.value)
    .map(stringToLocalDate) --> dateOfBirthUpdater,
  _.events.onChange.map(_.detail.value).map(stringToLocalDate) --> dateOfBirthUpdater,
  _.valueState <-- dateOfBirthErrorEvents.map(if _ then ValueState.Error else ValueState.None),
  _.events.onChange.mapTo(()) --> dateOfBirthErrorBus.writer,
  _.minDate := BabyForm.minDate,
  _.maxDate := BabyForm.maxDate
)

The localDateToString and stringToLocalDate functions are available in the DatePicker object.

Let me know if that example is speaking to you. Otherwise feel free to ask further.

:-)... thx