Commits

Matthew Schinckel  committed 70ce16c

Remove validationElement binding handler.

  • Participants
  • Parent commits ebcee30

Comments (0)

Files changed (2)

 ## Knockout Bindings
 
 
-    <form data-bind="allValid: $root, submit: sendData">
+    <form data-bind="requireValid: $root, submit: sendData">
       <input type="text" data-bind="value: someValue">
       <!-- validation errors will automatically be inserted here -->
       <input type="submit" value="Okay">
     </form>
 
-`allValid` ensures that all properties are valid: it disables submit on forms, or the element itself if it isn't a form, until validation is successful.
+`requireValid` ensures that all properties are valid: it disables submit on forms, or the element itself if it isn't a form, until validation is successful.
 
+Note I have used a different philosophy to Knockout-validation. This plugin _always_ creates it's own error display element. You can customise it.
 
+
+## Custom error display
+
+The default value is:
+
+    ko.subscribable.fn.validate.validationMessageTemplate = "<label class='help-inline'></label>";
+
+You can change what this should look like by changing the element.
+
+If the created element is an `<ul>`, then it will put each validation error as an `<li>`, else it will seperate them with `<br>`.
+  
 ## Included validators
 
 * required
 * maxLength
 * regex
 
-These are all demonstrated in `examples/index.html`.
-
-## Custom error display
-
-The default value is:
-
-    ko.subscribable.fn.validate.validationMessageTemplate = "<label class='help-inline'></label>";
-
-You can change what this should look like by changing the element.
-
-If the created element is an `<ul>`, then it will put each validation error as an `<li>`, else it will seperate them with `<br>`.
+These are all demonstrated in `examples/index.html`, as are custom one-off validators.

File src/knockout.validators.js

         value.errors.subscribe(validationMessage);
         validationMessage(value.errors());
       }
-
-    };
-    
-    // We also want to create a bindingHandler for displaying validation classes.
-    ko.bindingHandlers.validationElement = {
-      update: function(element, valueAccessor, allBindingsAccessor, viewModel) {
-        var value = valueAccessor();
-        if (value.hasErrors && value.hasErrors()){
-          $(element).addClass('error');
-        } else {
-          $(element).removeClass('error');
-        }
-      }
     };
     
     // We can also have a bindingHandler that all fields within a viewModel are valid.