title: AngularJS: How do I manually set input to $valid in controller?
body: <p>Using the <a href="http://loopj.com/jquery-tokeninput/" rel="noreferrer">TokenInput</a> plugin and using AngularJS built-in formController validation.</p>
  
  <p>Right now I'm trying to check if the field contains text, and then set field to valid if it does. The issue with using the plugin is it creates it's own input and then a ul+li for stlying.</p>
  
  <p>I have access to addItem (formname) and my capablities in the controller, I just need to set it to $valid.</p>
  
  <p>Markup.</p>
  
  <pre><code>&lt;form class="form-horizontal add-inventory-item" name="addItem"&gt;
       &lt;input id="capabilities" name="capabilities" token-input data-ng-model="inventoryCapabilitiesAutoComplete" data-on-add="addCapability()" data-on-delete="removeCapability()" required&gt;
       &lt;div class="required" data-ng-show="addItem.capabilities.$error.required" title="Please enter capability."&gt;&lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>JS.</p>
  
  <pre><code>$scope.capabilityValidation = function (capability) {
    if (capability.name !== "") {
      addItem.capabilities.$valid = true;
      addItem.capabilities.$error.required = false;
    } else {
      addItem.capabilities.$valid = false;
      addItem.capabilities.$error.required = true;
    }
  };
  </code></pre>
  
  <p>I'm running the capabilityValidation function when TokenInput has something entered and passing in the object.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Found out ng-model on my input does stuff and gets the autocomplete results, which is why I can't get ng-valid to work since it's based on the model.</p>
  
  <pre><code>$scope.inventoryCapabilitiesAutoComplete = {
    options: {
      tokenLimit: null
    },
    source: urlHelper.getAutoComplete('capability')
  };
  </code></pre>
  
  <p>I didn't write this autocomplete implementation, is there another way to do this where I would have access to the ng-model attr and move the model function somewhere else?</p>