From c34584db233c0f70153f579758310c884638b407 Mon Sep 17 00:00:00 2001 From: Olena Pastushenko Date: Sat, 16 Jun 2018 09:27:56 +0200 Subject: [PATCH] Use pull request #11035 from lirael/docs/abide-fix-custom-validator-foundation-initialization for v6.5.0 dded67fdb docs: fix example for custom validator 3bfb07b07 docs: add infos in the Abide custom validator example Co-Authored-By: Nicolas Coden Signed-off-by: Nicolas Coden --- docs/pages/abide.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/docs/pages/abide.md b/docs/pages/abide.md index c22716d63..86428a731 100644 --- a/docs/pages/abide.md +++ b/docs/pages/abide.md @@ -354,21 +354,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'] = - -// Init Foundation -$(document).foundation(); - -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)); }; + +// Set default options +Foundation.Abide.defaults.patterns['dashes_only'] = /^[0-9-]*$/; +Foundation.Abide.defaults.validators['greater_than'] = myCustomValidator; + +// Initialize Foundation +$(document).foundation(); ``` ```html -- 2.47.3