Bind slider max option to observable value

Bind slider max option to observable value

Hello and happy new year: 

I have a problem to bind the max option of my jquery slider to an ko.observable value. 

I´ve got the following error massage maybe you can help me. 


Unable to process binding "slider: function (){return {  min:10,max:max,step:10} }"
Message: cannot call methods on slider prior to initialization; attempted to call method 'max'
This is my code: 

  1. <div data-role="content">

  2.     <div>
  3.         <input data-bind="textinput: max"></input>
  4.     </div>
  5.     <div>
  6.         <span data-bind="text: value1"></span>
  7.     </div>

  8.     <div>
  9.         <label for="Range1Slider">GRP:</label>
  10.         <input type="range" name="Range1Slider" data-bind="slider: {  min: 10, max: max, step: 10 }" />
  11.     </div>


  12. </div>


  13. <script type="text/javascript">

  14.     function ViewModel() {

  15.         ///////////////////////////////////////////////////////////////////////////////////////////
  16.         //KnockoutJS Form Variablen
  17.         //////////////////////////////////////////////////////////////////////////////////////////

  18.         var self = this;

  19.         self.max = ko.observable(200);
  20.         self.value1 = ko.observable(20);
  21.     }
  22.     

  23.      ko.bindingHandlers.slider = {
  24.         init: function (element, valueAccessor, allBindings, ViewModel, bindingContext) {
  25.             var options = ko.unwrap(valueAccessor()),
  26.                 valueObservable = allBindings().value;

  27.             // to your init work for the slider-plugin
  28.             // maybe the following ?
  29.             $(element).slider('max', options.max());

  30.             // logic for element-disposal should be implemented

  31.         },
  32.         update: function (element, valueAccessor, allBindings, ViewModel, bindingContext) {
  33.             var options = ko.unwrap(valueAccessor()),
  34.                 valueObservable = allBindings().value;

  35.             // this will be called if the value-binding changed or the max-observable changed
  36.             // update the max-option
  37.             // maybe the following ?
  38.             $(element).slider('max', options.max());
  39.         }
  40.     }

  41.    ko.applyBindings(ViewModel);
  42. </script>