]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
docs: add infos in the Abide custom validator example 11035/head
authorNicolas Coden <nicolas@ncoden.fr>
Sat, 10 Mar 2018 21:01:39 +0000 (22:01 +0100)
committerNicolas Coden <nicolas@ncoden.fr>
Sat, 10 Mar 2018 21:01:39 +0000 (22:01 +0100)
docs/pages/abide.md

index 92442c0d0aba71a0d2381883843e318e72571d85..d150beb6759fee729c7246cc74d4828037d026d5 100644 (file)
@@ -345,22 +345,23 @@ website: {
 * Add new patterns and validators before or after foundation is initialized
 
 ```javascript
-
-// Set paramaters
-Foundation.Abide.defaults.patterns['dashes_only'] = /^[0-9-]*$/;
-Foundation.Abide.defaults.validators['greater_than'] =
-
-function($el,required,parent) {
-  // parameter 1 is jQuery selector
+function myCustomValidator(
+  $el,      /* jQuery element to validate */
+  required, /* is the element required according to the `[required]` attribute */
+  parent    /* parent of the jQuery element `$el` */
+) {
   if (!required) return true;
   var from = $('#'+$el.attr('data-greater-than')).val(),
       to = $el.val();
   return (parseInt(to) > parseInt(from));
 };
 
-// Init Foundation
-$(document).foundation();
+// Set default options
+Foundation.Abide.defaults.patterns['dashes_only'] = /^[0-9-]*$/;
+Foundation.Abide.defaults.validators['greater_than'] = myCustomValidator;
 
+// Initialize Foundation
+$(document).foundation();
 ```
 ```html
 <input id="phone" type="text" pattern="dashes_only" required >