2

I have a datepicker whose max selectable date is six months in the future. And if I select a checkbox, the max selectable date can be any time in the future. I'm trying to do this with Knockout.js.

This would be my date picker input options:

<input id="newRequestStartDate"
       type="text"
       data-bind="sfDatePicker: request.startDate, sfDatePickerOptions: startDateOptions, disable: summaryHasInvalidDays()"
       id="newTimeOffRequestStartDate"
       class="sf-form-input"
       data-range-group="ptoRange"
       name="newTimeOffRequestStartDate"
/>

This would be my checkbox input:

<input type="checkbox"
       id="globalOverrideCheckbox"
       data-bind="checked: request.isGlobalOverride, disable: summaryHasInvalidDays()"
/>

I have a subscribe binding based on this:

self.request.isGlobalOverride.subscribe(self.updateMaxAllowableDateInFuture);

and the code for subscribable is:

this.updateMaxAllowableDateInFuture = (function (isGlobalOverrideSet) {
     if (isGlobalOverrideSet) {
          _maxAllowableDateInFuture = _dateTenYearsFromNow;
          //this.startDateOptions.maxDate = _maxAllowableDateInFuture;
          self.destroyDatePicker();
     }
     return _maxAllowableDateInFuture;
});
4

1 回答 1

0

两步:

  1. 将 maxDate 更改为 observable,并直接在绑定中包含 maxDate(这可能需要修改 sfDatePicker 绑定器)。

  2. 更新 sfDatePicker 绑定,以便在 maxDate 可观察值更改时更改日期选择器上的设置。

如果您想了解更多详细信息,请提供 sfDatePicker 活页夹的代码

于 2014-08-28T20:22:48.320 回答