title: JavaScript Model Form Validation
body: <p>I am using BackboneJS MVC pattern and have a form with 2 fields which the user can select.</p>
  
  <p>I call changeAction whenever there is any change in selection by the user (to call validation);</p>
  
  <pre><code>changeAction: function (event) {
      var self = this;
      var target = event.target;
  
      target.value = $.trim(target.value);
      change[target.name] = target.value;
      this.model.set(change);
  
      var check = self.model.validateItem(target.id);
      if (check.isValid === false) {
          self.addValidationError(target.id, check.message);
      } else {
          self.removeValidationError(target.id);
      }
  }
  </code></pre>
  
  <p>My validation is defined in the Model as below;</p>
  
  <pre><code>this.validators.myDropDownField = function(value) {
      return !_.isUndefined(value) &amp;&amp; !_.isNull(value) &amp;&amp; $.trim(value).length &gt; 0 ? {
          isValid: true
      } : {
          isValid: false,
          message: "Select dropdown field"
      };
  };
  
  validateItem: function(key) {
      var result = (this.validators[key]) ? this.validators[key](this.get(key)) : {
          isValid: true
      };
      return result;
  }
  </code></pre>
  
  <p>Now my question is I do not want to do anything to the Model in changeAction.
  But if I remove the line <code>this.model.set(change)</code> in <code>changeAction()</code></p>
  
  <p>the validation does not work correctly. I do not get the value in the function</p>
  
  <blockquote>
    <p>this.validators.myDropDownField</p>
  </blockquote>
  
  <p>How do I handle this ?</p>