title: Knockout.js - Change other observables in viewmodel from extender or other way to do something similar
body: <p>I've been doing some simple knockout things before, but this one feels a more complicated.
  A client wishes to be able to control the number of order rows in a form with the help of a dropdown (I asked why they didn't want a regular add button, but they said this would give them better overview that everything was filled out...).</p>
  
  <p>I have an observable holding the value from the dropdown and an observableArray to hold the order rows, but I had to confirm the selection was intended when the new value is less than the previous.</p>
  
  <p>So I started scouring the internet for tips and tricks how to accomplish this.
  First I found <a href="https://stackoverflow.com/a/21482696/2814279">this "confirmable" extender</a>. It helped me show a confirm dialog if the number of rows they selected was less than the previous value, but I found no way to interact with other observables in the viewmodel from it.</p>
  
  <p>So I Google'd some more and found <a href="https://github.com/knockout/knockout/pull/520" rel="nofollow noreferrer">the first answer from Michael Best here</a>. With the "subscribeChanged" function I could now (after the confirmable extender did its part) add or remove rows to the observable array of order rows.</p>
  
  <p>However. I would like for there to be some better way to accomplish this in order to not have the almost exact code in more than one place. Because now I have this code in the extender</p>
  
  <pre><code>if (!isValidateInteger(current) &amp;&amp; isValidateInteger(newValue)) {
      target(newValue);
      // TODO: Add rows to vm.orderRows so the count reflects newValue
  }
  </code></pre>
  
  <p>and this code in subscribeChanged function</p>
  
  <pre><code>if (!isValidateInteger(current) &amp;&amp; isValidateInteger(newValue)) {
      // NOTE: Add rows to vm.orderRows so the count reflects newValue
      difference = (newValueInt - currentInt);
      message += '&lt;br /&gt;Add ' + difference + ' row(s).';
      for (var i = 0; i &lt; difference; i++) {
          vm.orderRows().push(new OrderRow());
      }
      vm.orderRows.valueHasMutated();
  }
  </code></pre>
  
  <p>I've put together <a href="http://jsfiddle.net/BVtd7/" rel="nofollow noreferrer">this fiddle</a> with an excerpt of the code I have today. </p>
  
  <p>I know some of the if-statements don't need to be there, but they're for debugging purpose at the moment. I will look at which to remove when the functionality is completed and tested, but any pointers (even ones not pertaining the question) are welcome.</p>
  
  <p>Thanks in advance, Ludvig</p>