Commits

Matthew Schinckel committed 2327cf9

Nicer handling for <ul> error display.
When a <ul> is detected as the container for errors, we use <li> items instead of <br> as the seperator.

Comments (0)

Files changed (2)

       <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.
+
 
 ## Included validators
 
 * maxLength
 * regex
 
-These are all demonstrated in `examples/index.html`.
+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>`.

src/knockout.validators.js

         $validationMessageElement.insertAfter($element);
         // Append/remove the validation message
         var validationMessage = function(message) {
-          $validationMessageElement.html(message.join("<br>"));
+          if ($validationMessageElement[0].tagName === "UL") {
+            $validationMessageElement.html("<li>" + message.join('</li><li>') + '</li>')
+          } else {
+            $validationMessageElement.html(message.join("<br>"));
+          }
           // Also apply the error class to relevant elements.
           // Note that this is not sufficient for Bootstrap: you need to
           // have a class on 'error' on a parent div, and a .control-group if there is one.