Search code examples
jquery-ui-datepickerjsrenderjsviews

Disable jsviews datepicker depending on another value


I need to disable a datepicker depending on the value of another property in the model.

How can I achieve this?

I know i can disable it by setting _disabled=true|false but can I also include conditional expression and what is the syntax. I need to be able to react to the changes in the other property and have the date picker update disable state accordingly. The other property is a data linked select with numeric values.

Something like

{^{datepicker 
  _disabled="{:OtherProperty > 1}}
  DatePickerValue
  dataFormat="mm/dd/yy"
  dateFormat="dd/mm/yy"
{{/datepicker}}"

Is this possible and how can I do this?


Solution

  • Yes, you can do that.

    You can put an expression directly as a value of a tag property: _disabled=OtherProperty > 1 - which will initialize the value.

    But by default, tag properties are not data-linked for dynamic changes. You have to opt in to that by prepending a ^. See Binding to named properties of tags, and also the section Data-linked option here

    See for example the dynamic binding of ^_numberOfMonths=... in the Datepicker variants sample.

    So in your case you need something like:

    {^{datepicker 
      ^_disabled=OtherProperty>1
      DatePickerValue
      dataFormat="mm/dd/yy"
      dateFormat="dd/mm/yy" /}}