Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/knockout/2.2.0/knockout-min.js"></script>
<script src="http://raw.github.com/ericmbarnard/Knockout-Validation/master/Src/knockout.validation.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  
  <ul data-bind="foreach: errors">
    <li class="error" data-bind="text: $data">      
    </li>
  </ul>  
  
  <label>Weekly max hours</label> <br />
    <div data-bind="foreach:WeeklyData">
    <input readonly="readonly" data-bind="value: $data"/><br />
   </div>    
  
</body>
</html>
 
var fminIncrements = function (valueArray) {
  var check = true;    
  ko.utils.arrayFirst(valueArray, 
     function(value){
        if(parseInt(value, 10) % 15 !== 0)
        {
          check = false;
          return true;
        }
     }); 
  return check;
};
function viewModel() { 
    var self = this;
    self.WeeklyData = ko.observableArray([
      15, 
      40
    ]).extend({ 
        validation: {
          validator: fminIncrements,
          message: "use 15 min increments" 
        }
    });
  
    self.errors = ko.validation.group(self);
}
ko.applyBindings(new viewModel());
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers