From: Nicolas Coden Date: Sat, 10 Mar 2018 21:01:39 +0000 (+0100) Subject: docs: add infos in the Abide custom validator example X-Git-Tag: v6.6.0~27^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F11035%2Fhead;p=thirdparty%2Ffoundation%2Ffoundation-sites.git docs: add infos in the Abide custom validator example --- diff --git a/docs/pages/abide.md b/docs/pages/abide.md index 92442c0d0..d150beb67 100644 --- a/docs/pages/abide.md +++ b/docs/pages/abide.md @@ -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