├── .gitignore ├── .gitmodules ├── .versions ├── README.md ├── package.js ├── themeteorchef:jquery-validation-tests.js └── versions.json /.gitignore: -------------------------------------------------------------------------------- 1 | .build* 2 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/jquery-validation"] 2 | path = lib/jquery-validation 3 | url = https://github.com/jzaefferer/jquery-validation 4 | -------------------------------------------------------------------------------- /.versions: -------------------------------------------------------------------------------- 1 | base64@1.0.3 2 | binary-heap@1.0.3 3 | callback-hook@1.0.3 4 | check@1.0.5 5 | ddp@1.1.0 6 | ejson@1.0.6 7 | geojson-utils@1.0.3 8 | id-map@1.0.3 9 | jquery@1.11.3_2 10 | json@1.0.3 11 | local-test:themeteorchef:jquery-validation@1.14.0 12 | logging@1.0.7 13 | meteor@1.1.6 14 | minimongo@1.0.8 15 | mongo@1.1.0 16 | ordered-dict@1.0.3 17 | random@1.0.3 18 | retry@1.0.3 19 | test-helpers@1.0.4 20 | themeteorchef:jquery-validation@1.14.0 21 | tinytest@1.0.5 22 | tracker@1.0.7 23 | underscore@1.0.3 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | +++++ DEPRECATION NOTICE +++++ 2 | 3 | This package is no longer being maintained. **It's recommended that you rely on the official jquery-validation package via NPM**. 4 | 5 | **To get it**: `npm install --save jquery-validation` 6 | 7 | --- 8 | 9 | ## jQuery Validation for Meteor 10 | 11 | Meteor implementation of [Validation](https://github.com/jzaefferer/jquery-validation) for jQuery. 12 | 13 | ## Usage 14 | 15 | Install via [Atmosphere](http://atmospherejs.com): 16 | 17 | ` meteor add themeteorchef:jquery-validation` 18 | 19 | ### Basic Implementation 20 | 21 | There are a number of ways to validate your forms. The first and most simplistic is to use the helper classes provided by jQuery Validation in your markup. In the following example, the `.required` and `.email` classes are being used. On the name input, the `class="required"` attribute tells jQuery Validation that this field is required. If a user fails to type anything into this field, an error will be thrown. 22 | 23 | On the second field (`name="emailAddress"`), we see two classes in use: `class="required email"`. Similar to the first field, this means that a value is required in this field, but *also* means that the user's input needs to be a valid email address (e.g. `email@website.com` and not `aetoiuetoi90385135`). 24 | 25 | Add the "required" class to your markup: 26 | 27 | ``` 28 | 37 | ``` 38 | 39 | Back in our Meteor code, we enable validation by using the `.validate()` method provided by jQuery Validation in our template's rendered function: 40 | 41 | ``` 42 | Template.exampleForm.onRendered( function() { 43 | $( "#example-form" ).validate(); 44 | }); 45 | ``` 46 | 47 | ### Advanced Implementation 48 | 49 | If need be, you can make use of all of [jQuery Validation's methods](http://jqueryvalidation.org/validate). To use them in your Meteor app, see the example below for adding validation to the login form in [Base](http://themeteorchef.com/base). 50 | 51 | First, our markup. Note: instead of adding classes, we're only using bare markup here. jQuery Validation relies on the `name` attribute of our form fields to define rules. 52 | 53 | ``` 54 | 75 | ``` 76 | 77 | Next, in our controller file (where we store our Meteor code), we want to prevent a submission on the `
` element: 78 | 79 | ``` 80 | Template.login.events({ 81 | 'submit form': ( event ) => event.preventDefault() 82 | }); 83 | ``` 84 | 85 | Finally, we call the `.validate()` method in our form when our template is rendered (note: the way this is done in Base is a little bit different and has been simplified here): 86 | 87 | ``` 88 | Template.login.onRendered( function() { 89 | $( '#login' ).validate({ 90 | rules { 91 | emailAddress: { 92 | required: true, 93 | email: true 94 | }, 95 | password { 96 | required: true 97 | } 98 | }, 99 | messages: { 100 | emailAddress: { 101 | required: "Please enter your email address to login.", 102 | email: "Please enter a valid email address." 103 | }, 104 | password { 105 | required: "Please enter your password to login." 106 | } 107 | }, 108 | submitHandler() { 109 | let email = $( '[name="emailAddress"]' ).val(), 110 | password = $('[name="password"]').val(); 111 | 112 | Meteor.loginWithPassword( email, password, ( error ) => { 113 | if ( error ) { 114 | alert( error.reason ); 115 | } 116 | }); 117 | } 118 | }); 119 | ``` 120 | 121 | In the example above, you can see the required and email methods being used. 122 | 123 | For more custom validation options and configuration, check out the jQuery validation documentation: [jQuery Validation Documentation](http://jqueryvalidation.org/documentation) 124 | -------------------------------------------------------------------------------- /package.js: -------------------------------------------------------------------------------- 1 | Package.describe({ 2 | summary: "jQuery Validation by jzaefferer, repackaged for Meteor.", 3 | version: "1.14.0", 4 | name: "themeteorchef:jquery-validation", 5 | git: "https://github.com/themeteorchef/jquery-validation" 6 | }); 7 | 8 | Package.onUse(function(api) { 9 | api.versionsFrom('METEOR@0.9.3'); 10 | api.use('jquery'); 11 | api.addFiles([ 12 | 'lib/jquery-validation/src/core.js', 13 | 'lib/jquery-validation/src/ajax.js', 14 | 'lib/jquery-validation/src/additional/pattern.js' 15 | ],'client'); 16 | }); 17 | 18 | Package.onTest(function(api) { 19 | api.use(['tinytest', 'test-helpers'], ['client', 'server']); 20 | api.use('jquery', 'client'); 21 | api.use('themeteorchef:jquery-validation'); 22 | api.addFiles('themeteorchef:jquery-validation-tests.js'); 23 | }); 24 | -------------------------------------------------------------------------------- /themeteorchef:jquery-validation-tests.js: -------------------------------------------------------------------------------- 1 | // Nothing here yet. 2 | -------------------------------------------------------------------------------- /versions.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": [ 3 | [ 4 | "jquery", 5 | "1.0.1" 6 | ], 7 | [ 8 | "meteor", 9 | "1.1.3" 10 | ], 11 | [ 12 | "underscore", 13 | "1.0.1" 14 | ] 15 | ], 16 | "pluginDependencies": [], 17 | "toolVersion": "meteor-tool@1.0.35", 18 | "format": "1.0" 19 | } 20 | --------------------------------------------------------------------------------