diff --git a/README.md b/README.md index 97ad261..e6c0d91 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ Access a [live demo](http://www.vmichnowicz.com/examples/formvalidate/index.html jQuery Form Validate is a jQuery plugin that helps validate your HTML forms. It takes validation rules from the HTML 5 data attributes applied to each input. For example, let's assume we have a `first_name` text input in our form. We want our first name field to be required and have a length of at least 5 characters. The HTML markup would look like this: -```` +``` -```` +``` ## Filters & Validations @@ -46,7 +46,7 @@ jQuery Form Validate uses the data attributes applied to your form inputs input ### messageParent -CSS selector of parent element of message (success or failure) messages. By default this is `div`. +CSS selector of parent element of success and failure message. By default this is `div`. This selector is relative to each input. Starting at the input we go through each parent and see if it matches the provided selector. This will tell us were to place each error and success messages. For this reason it is nice to wrap each set of labels and inputs in some sort of container element. ### messageElement @@ -62,25 +62,25 @@ Boolean option to display success messages. Defaults to `false`. ### messageFailureClass -CSS class(es) applied to failure messages. Defaults to `error`. Multiple CSS classes can be applied by through space deliineation i.e. `error error-text`. +CSS class(es) applied to failure messages. Defaults to `error`. Multiple CSS classes can be applied by through space delineation i.e. `error error-text`. ### messageSuccessClass -CSS class(es) applied to success messages. Defaults to `success`. Multiple CSS classes can be applied by through space deliineation i.e. `success success-text`. +CSS class(es) applied to success messages. Defaults to `success`. Multiple CSS classes can be applied by through space delineation i.e. `success success-text`. ### inputFailureClass -CSS class(es) added to inputs that did not pass validation. Defaults to `error`. Multiple CSS classes can be applied by through space deliineation i.e. `error error-text`. +CSS class(es) added to inputs that did not pass validation. Defaults to `error`. Multiple CSS classes can be applied by through space delineation i.e. `error error-text`. ### inputSuccessClass -CSS class added to inputs that did pass validation. Defaults to `success`. Multiple CSS classes can be applied by through space deliineation i.e. `success success-text`. +CSS class added to inputs that did pass validation. Defaults to `success`. Multiple CSS classes can be applied by through space delineation i.e. `success success-text`. ### language -Set the language for error and success messages. Defaults to `en` for English. Deutsch `de`, English `en`, Espańol `es`, and Pirate `pirage` are available. +Set the language for error and success messages. Defaults to `en` for English. Deutsch `de`, English `en`, Español `es`, and Pirate `pirate` are available. -## Publically Available Methods +## Publicly Available Methods ### preProcess [ function *function(form, options, inputFailureClass, inputSuccessClass, messageFailureClass, messageSuccessClass, messageElement)* ] @@ -229,4 +229,4 @@ This function checks to see if a value is greater than the provided number. * required * requiredIf * lessThan - * greaterThan \ No newline at end of file + * greaterThan diff --git a/package.json b/formvalidate.jquery.json similarity index 57% rename from package.json rename to formvalidate.jquery.json index 70d8ef5..9647d9a 100644 --- a/package.json +++ b/formvalidate.jquery.json @@ -1,27 +1,30 @@ { "name": "formvalidate", - "version": "0.1.1", "title": "jQuery Form Validate", + "description": "jQuery Form Validate is a simple form validation plugin that allows you to easily validate your forms by applying various HTML data attributes.", + "version": "0.4.2", "author": { "name": "Victor Michnowicz", "url": "http://www.vmichnowicz.com/" }, "licenses": [ { - "type": "MIT", - "url": "http://opensource.org/licenses/MIT" + "type": "MIT", + "url": "http://opensource.org/licenses/MIT" } ], "dependencies": { "jquery": ">1.4.3" }, - "description": "", "keywords": [ "form", "validation", "validate" ], "homepage": "https://github.com/vmichnowicz/jquery.formvalidate", + "bugs": "https://github.com/vmichnowicz/jquery.formvalidate/issues", + "docs": "https://github.com/vmichnowicz/jquery.formvalidate/wiki", + "demo": "http://www.vmichnowicz.com/examples/formvalidate/index.html", "maintainers": [ { "name": "Victor Michnowicz", diff --git a/fr.js b/fr.js new file mode 100644 index 0000000..de4d55e --- /dev/null +++ b/fr.js @@ -0,0 +1,30 @@ +/** + * jQuery Form Validate French error message translations (translation by https://github.com/lpfrenette) + * + * Include this file *after* the jquery.formvalidate.js in document + */ +jQuery.extend(true, jQuery.fn.formvalidate.options.localization, { + fr: { + failure: { + 'default': '{0} est invalide.', + betweenNumeric: '{0} doit ĂȘtre entre {2} et {3}.', + date: '{0} n\'est pas une date valide.', + email: '{1} n\'est pas un courriel valide.', + numChars: '{0} doit ĂȘtre exactement {2}.', + minChars: '{0} doit ĂȘtre au moins {2}.', + maxChars: '{0} ne peut ĂȘtre supĂ©rieur Ă  {2}.', + numOptions: 'Ahoy , yee must select exactly {2} options.', + minOptions: 'Vous devez sĂ©lectionner au moins {2} options.', + maxOptions: 'Vous ne pouvez sĂ©lectionner plus de {2} options.', + 'int': '{0} n\'est pas un entier.', + 'float': '{0} n\'est pas un nombre valide.', + required: '{0} est requis.', + requiredIf: '{0} est requis.', + lessThan: '{0} doit ĂȘtre moins de {2}.', + greaterThan: '{0} doit ĂȘtre suppĂ©rieur Ă  {2}.' + }, + success: { + 'default': '{0} est valide!' + } + } +}); diff --git a/index.html b/index.html index e276ab5..d17dbcb 100644 --- a/index.html +++ b/index.html @@ -3,6 +3,7 @@ jQuery Form Validate + @@ -98,7 +99,7 @@
- +
@@ -254,6 +255,11 @@ onSuccess: function(form) { alert('Form #2 is valid!'); }, + validations: { + isNot: function(input, params) { + return $.inArray(input.toLowerCase(), params); + } + }, localization: { en: { success: { @@ -276,6 +282,9 @@ failure: { email: function(title, value, name, input) { return 'There is no way that email ' + value + ' is valid.'; + }, + isNot: function(title, value, name, input) { + return 'That name is not original enough.'; } } } diff --git a/jquery.formvalidate.js b/jquery.formvalidate.js index 14cefe9..fa8eb5c 100644 --- a/jquery.formvalidate.js +++ b/jquery.formvalidate.js @@ -301,15 +301,31 @@ // If title had not yet been created for this input if ( ! ('title' in inputs[attrName]) ) { + var title = null; + // Check for title data-title attribute if ('title' in data) { - inputs[attrName].title = data.title; + title = data.title; } - // If no title data-title attribute is found, use the inputs name attribute - else { + + // If still no title, use the inputs title attribute + if ( ! title ) { // Look for the first input that has this same name attribe and a title attribute and grab its title - inputs[attrName].title = $(':input[name="' + attrName + '"][title!=""]:first').attr('title'); + title = $(':input[name="' + attrName + '"][title!=""]:first').attr('title'); + } + + // If still no title, check associated label + if ( ! title ) { + var id = $(':input[name="' + attrName + '"][id!=""]:first').attr('id'); + title = $('label[for="' + id + '"]').text(); + } + + // If still no title, check parent label + if ( ! title ) { + title = $('label :input[name="' + attrName + '"]:first').closest('label').text(); } + + inputs[attrName].title = title; } // Set success and failure in object