Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix example for custom validator #11035

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions docs/pages/abide.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,21 +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'] =

// 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
<input id="phone" type="text" pattern="dashes_only" required >
Expand Down