annotate Agendas/trunk/src/Agendas.Web/Scripts/jquery.validate.js @ 55:39f5258ebdcf

Agregando referencias con NuGet
author nelopauselli
date Mon, 16 May 2011 20:10:45 -0300
parents c62b77fc33f4
children
rev   line source
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1 /*
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
2 * Note: While Microsoft is not the author of this file, Microsoft is
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
3 * offering you a license subject to the terms of the Microsoft Software
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
4 * License Terms for Microsoft ASP.NET Model View Controller 3.
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
5 * Microsoft reserves all other rights. The notices below are provided
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
6 * for informational purposes only and are not the license terms under
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
7 * which Microsoft distributed this file.
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
8 *
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
9 * jQuery validation plug-in 1.7
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
10 *
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
11 * http://bassistance.de/jquery-plugins/jquery-plugin-validation/
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
12 * http://docs.jquery.com/Plugins/Validation
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
13 *
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
14 * Copyright (c) 2006 - 2008 Jörn Zaefferer
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
15 *
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
16 * $Id: jquery.validate.js 6403 2009-06-17 14:27:16Z joern.zaefferer $
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
17 *
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
18 */
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
19
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
20 (function($) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
21
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
22 $.extend($.fn, {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
23 // http://docs.jquery.com/Plugins/Validation/validate
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
24 validate: function( options ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
25
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
26 // if nothing is selected, return nothing; can't chain anyway
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
27 if (!this.length) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
28 options && options.debug && window.console && console.warn( "nothing selected, can't validate, returning nothing" );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
29 return;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
30 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
31
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
32 // check if a validator for this form was already created
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
33 var validator = $.data(this[0], 'validator');
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
34 if ( validator ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
35 return validator;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
36 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
37
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
38 validator = new $.validator( options, this[0] );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
39 $.data(this[0], 'validator', validator);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
40
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
41 if ( validator.settings.onsubmit ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
42
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
43 // allow suppresing validation by adding a cancel class to the submit button
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
44 this.find("input, button").filter(".cancel").click(function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
45 validator.cancelSubmit = true;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
46 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
47
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
48 // when a submitHandler is used, capture the submitting button
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
49 if (validator.settings.submitHandler) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
50 this.find("input, button").filter(":submit").click(function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
51 validator.submitButton = this;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
52 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
53 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
54
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
55 // validate the form on submit
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
56 this.submit( function( event ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
57 if ( validator.settings.debug )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
58 // prevent form submit to be able to see console output
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
59 event.preventDefault();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
60
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
61 function handle() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
62 if ( validator.settings.submitHandler ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
63 if (validator.submitButton) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
64 // insert a hidden input as a replacement for the missing submit button
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
65 var hidden = $("<input type='hidden'/>").attr("name", validator.submitButton.name).val(validator.submitButton.value).appendTo(validator.currentForm);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
66 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
67 validator.settings.submitHandler.call( validator, validator.currentForm );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
68 if (validator.submitButton) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
69 // and clean up afterwards; thanks to no-block-scope, hidden can be referenced
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
70 hidden.remove();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
71 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
72 return false;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
73 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
74 return true;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
75 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
76
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
77 // prevent submit for invalid forms or custom submit handlers
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
78 if ( validator.cancelSubmit ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
79 validator.cancelSubmit = false;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
80 return handle();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
81 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
82 if ( validator.form() ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
83 if ( validator.pendingRequest ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
84 validator.formSubmitted = true;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
85 return false;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
86 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
87 return handle();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
88 } else {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
89 validator.focusInvalid();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
90 return false;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
91 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
92 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
93 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
94
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
95 return validator;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
96 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
97 // http://docs.jquery.com/Plugins/Validation/valid
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
98 valid: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
99 if ( $(this[0]).is('form')) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
100 return this.validate().form();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
101 } else {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
102 var valid = true;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
103 var validator = $(this[0].form).validate();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
104 this.each(function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
105 valid &= validator.element(this);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
106 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
107 return valid;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
108 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
109 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
110 // attributes: space seperated list of attributes to retrieve and remove
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
111 removeAttrs: function(attributes) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
112 var result = {},
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
113 $element = this;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
114 $.each(attributes.split(/\s/), function(index, value) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
115 result[value] = $element.attr(value);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
116 $element.removeAttr(value);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
117 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
118 return result;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
119 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
120 // http://docs.jquery.com/Plugins/Validation/rules
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
121 rules: function(command, argument) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
122 var element = this[0];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
123
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
124 if (command) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
125 var settings = $.data(element.form, 'validator').settings;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
126 var staticRules = settings.rules;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
127 var existingRules = $.validator.staticRules(element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
128 switch(command) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
129 case "add":
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
130 $.extend(existingRules, $.validator.normalizeRule(argument));
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
131 staticRules[element.name] = existingRules;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
132 if (argument.messages)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
133 settings.messages[element.name] = $.extend( settings.messages[element.name], argument.messages );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
134 break;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
135 case "remove":
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
136 if (!argument) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
137 delete staticRules[element.name];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
138 return existingRules;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
139 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
140 var filtered = {};
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
141 $.each(argument.split(/\s/), function(index, method) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
142 filtered[method] = existingRules[method];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
143 delete existingRules[method];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
144 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
145 return filtered;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
146 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
147 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
148
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
149 var data = $.validator.normalizeRules(
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
150 $.extend(
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
151 {},
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
152 $.validator.metadataRules(element),
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
153 $.validator.classRules(element),
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
154 $.validator.attributeRules(element),
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
155 $.validator.staticRules(element)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
156 ), element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
157
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
158 // make sure required is at front
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
159 if (data.required) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
160 var param = data.required;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
161 delete data.required;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
162 data = $.extend({required: param}, data);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
163 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
164
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
165 return data;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
166 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
167 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
168
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
169 // Custom selectors
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
170 $.extend($.expr[":"], {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
171 // http://docs.jquery.com/Plugins/Validation/blank
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
172 blank: function(a) {return !$.trim("" + a.value);},
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
173 // http://docs.jquery.com/Plugins/Validation/filled
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
174 filled: function(a) {return !!$.trim("" + a.value);},
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
175 // http://docs.jquery.com/Plugins/Validation/unchecked
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
176 unchecked: function(a) {return !a.checked;}
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
177 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
178
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
179 // constructor for validator
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
180 $.validator = function( options, form ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
181 this.settings = $.extend( true, {}, $.validator.defaults, options );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
182 this.currentForm = form;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
183 this.init();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
184 };
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
185
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
186 $.validator.format = function(source, params) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
187 if ( arguments.length == 1 )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
188 return function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
189 var args = $.makeArray(arguments);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
190 args.unshift(source);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
191 return $.validator.format.apply( this, args );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
192 };
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
193 if ( arguments.length > 2 && params.constructor != Array ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
194 params = $.makeArray(arguments).slice(1);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
195 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
196 if ( params.constructor != Array ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
197 params = [ params ];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
198 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
199 $.each(params, function(i, n) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
200 source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
201 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
202 return source;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
203 };
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
204
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
205 $.extend($.validator, {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
206
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
207 defaults: {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
208 messages: {},
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
209 groups: {},
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
210 rules: {},
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
211 errorClass: "error",
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
212 validClass: "valid",
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
213 errorElement: "label",
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
214 focusInvalid: true,
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
215 errorContainer: $( [] ),
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
216 errorLabelContainer: $( [] ),
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
217 onsubmit: true,
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
218 ignore: [],
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
219 ignoreTitle: false,
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
220 onfocusin: function(element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
221 this.lastActive = element;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
222
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
223 // hide error label and remove error class on focus if enabled
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
224 if ( this.settings.focusCleanup && !this.blockFocusCleanup ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
225 this.settings.unhighlight && this.settings.unhighlight.call( this, element, this.settings.errorClass, this.settings.validClass );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
226 this.errorsFor(element).hide();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
227 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
228 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
229 onfocusout: function(element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
230 if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
231 this.element(element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
232 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
233 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
234 onkeyup: function(element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
235 if ( element.name in this.submitted || element == this.lastElement ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
236 this.element(element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
237 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
238 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
239 onclick: function(element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
240 // click on selects, radiobuttons and checkboxes
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
241 if ( element.name in this.submitted )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
242 this.element(element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
243 // or option elements, check parent select in that case
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
244 else if (element.parentNode.name in this.submitted)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
245 this.element(element.parentNode);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
246 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
247 highlight: function( element, errorClass, validClass ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
248 $(element).addClass(errorClass).removeClass(validClass);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
249 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
250 unhighlight: function( element, errorClass, validClass ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
251 $(element).removeClass(errorClass).addClass(validClass);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
252 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
253 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
254
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
255 // http://docs.jquery.com/Plugins/Validation/Validator/setDefaults
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
256 setDefaults: function(settings) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
257 $.extend( $.validator.defaults, settings );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
258 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
259
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
260 messages: {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
261 required: "This field is required.",
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
262 remote: "Please fix this field.",
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
263 email: "Please enter a valid email address.",
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
264 url: "Please enter a valid URL.",
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
265 date: "Please enter a valid date.",
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
266 dateISO: "Please enter a valid date (ISO).",
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
267 number: "Please enter a valid number.",
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
268 digits: "Please enter only digits.",
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
269 creditcard: "Please enter a valid credit card number.",
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
270 equalTo: "Please enter the same value again.",
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
271 accept: "Please enter a value with a valid extension.",
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
272 maxlength: $.validator.format("Please enter no more than {0} characters."),
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
273 minlength: $.validator.format("Please enter at least {0} characters."),
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
274 rangelength: $.validator.format("Please enter a value between {0} and {1} characters long."),
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
275 range: $.validator.format("Please enter a value between {0} and {1}."),
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
276 max: $.validator.format("Please enter a value less than or equal to {0}."),
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
277 min: $.validator.format("Please enter a value greater than or equal to {0}.")
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
278 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
279
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
280 autoCreateRanges: false,
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
281
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
282 prototype: {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
283
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
284 init: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
285 this.labelContainer = $(this.settings.errorLabelContainer);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
286 this.errorContext = this.labelContainer.length && this.labelContainer || $(this.currentForm);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
287 this.containers = $(this.settings.errorContainer).add( this.settings.errorLabelContainer );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
288 this.submitted = {};
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
289 this.valueCache = {};
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
290 this.pendingRequest = 0;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
291 this.pending = {};
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
292 this.invalid = {};
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
293 this.reset();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
294
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
295 var groups = (this.groups = {});
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
296 $.each(this.settings.groups, function(key, value) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
297 $.each(value.split(/\s/), function(index, name) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
298 groups[name] = key;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
299 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
300 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
301 var rules = this.settings.rules;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
302 $.each(rules, function(key, value) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
303 rules[key] = $.validator.normalizeRule(value);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
304 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
305
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
306 function delegate(event) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
307 var validator = $.data(this[0].form, "validator"),
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
308 eventType = "on" + event.type.replace(/^validate/, "");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
309 validator.settings[eventType] && validator.settings[eventType].call(validator, this[0] );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
310 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
311 $(this.currentForm)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
312 .validateDelegate(":text, :password, :file, select, textarea", "focusin focusout keyup", delegate)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
313 .validateDelegate(":radio, :checkbox, select, option", "click", delegate);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
314
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
315 if (this.settings.invalidHandler)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
316 $(this.currentForm).bind("invalid-form.validate", this.settings.invalidHandler);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
317 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
318
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
319 // http://docs.jquery.com/Plugins/Validation/Validator/form
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
320 form: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
321 this.checkForm();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
322 $.extend(this.submitted, this.errorMap);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
323 this.invalid = $.extend({}, this.errorMap);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
324 if (!this.valid())
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
325 $(this.currentForm).triggerHandler("invalid-form", [this]);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
326 this.showErrors();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
327 return this.valid();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
328 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
329
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
330 checkForm: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
331 this.prepareForm();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
332 for ( var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++ ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
333 this.check( elements[i] );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
334 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
335 return this.valid();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
336 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
337
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
338 // http://docs.jquery.com/Plugins/Validation/Validator/element
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
339 element: function( element ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
340 element = this.clean( element );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
341 this.lastElement = element;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
342 this.prepareElement( element );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
343 this.currentElements = $(element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
344 var result = this.check( element );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
345 if ( result ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
346 delete this.invalid[element.name];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
347 } else {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
348 this.invalid[element.name] = true;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
349 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
350 if ( !this.numberOfInvalids() ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
351 // Hide error containers on last error
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
352 this.toHide = this.toHide.add( this.containers );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
353 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
354 this.showErrors();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
355 return result;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
356 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
357
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
358 // http://docs.jquery.com/Plugins/Validation/Validator/showErrors
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
359 showErrors: function(errors) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
360 if(errors) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
361 // add items to error list and map
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
362 $.extend( this.errorMap, errors );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
363 this.errorList = [];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
364 for ( var name in errors ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
365 this.errorList.push({
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
366 message: errors[name],
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
367 element: this.findByName(name)[0]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
368 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
369 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
370 // remove items from success list
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
371 this.successList = $.grep( this.successList, function(element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
372 return !(element.name in errors);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
373 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
374 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
375 this.settings.showErrors
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
376 ? this.settings.showErrors.call( this, this.errorMap, this.errorList )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
377 : this.defaultShowErrors();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
378 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
379
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
380 // http://docs.jquery.com/Plugins/Validation/Validator/resetForm
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
381 resetForm: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
382 if ( $.fn.resetForm )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
383 $( this.currentForm ).resetForm();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
384 this.submitted = {};
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
385 this.prepareForm();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
386 this.hideErrors();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
387 this.elements().removeClass( this.settings.errorClass );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
388 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
389
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
390 numberOfInvalids: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
391 return this.objectLength(this.invalid);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
392 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
393
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
394 objectLength: function( obj ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
395 var count = 0;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
396 for ( var i in obj )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
397 count++;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
398 return count;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
399 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
400
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
401 hideErrors: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
402 this.addWrapper( this.toHide ).hide();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
403 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
404
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
405 valid: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
406 return this.size() == 0;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
407 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
408
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
409 size: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
410 return this.errorList.length;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
411 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
412
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
413 focusInvalid: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
414 if( this.settings.focusInvalid ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
415 try {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
416 $(this.findLastActive() || this.errorList.length && this.errorList[0].element || [])
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
417 .filter(":visible")
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
418 .focus()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
419 // manually trigger focusin event; without it, focusin handler isn't called, findLastActive won't have anything to find
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
420 .trigger("focusin");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
421 } catch(e) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
422 // ignore IE throwing errors when focusing hidden elements
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
423 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
424 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
425 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
426
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
427 findLastActive: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
428 var lastActive = this.lastActive;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
429 return lastActive && $.grep(this.errorList, function(n) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
430 return n.element.name == lastActive.name;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
431 }).length == 1 && lastActive;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
432 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
433
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
434 elements: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
435 var validator = this,
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
436 rulesCache = {};
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
437
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
438 // select all valid inputs inside the form (no submit or reset buttons)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
439 // workaround $Query([]).add until http://dev.jquery.com/ticket/2114 is solved
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
440 return $([]).add(this.currentForm.elements)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
441 .filter(":input")
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
442 .not(":submit, :reset, :image, [disabled]")
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
443 .not( this.settings.ignore )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
444 .filter(function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
445 !this.name && validator.settings.debug && window.console && console.error( "%o has no name assigned", this);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
446
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
447 // select only the first element for each name, and only those with rules specified
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
448 if ( this.name in rulesCache || !validator.objectLength($(this).rules()) )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
449 return false;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
450
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
451 rulesCache[this.name] = true;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
452 return true;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
453 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
454 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
455
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
456 clean: function( selector ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
457 return $( selector )[0];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
458 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
459
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
460 errors: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
461 return $( this.settings.errorElement + "." + this.settings.errorClass, this.errorContext );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
462 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
463
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
464 reset: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
465 this.successList = [];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
466 this.errorList = [];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
467 this.errorMap = {};
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
468 this.toShow = $([]);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
469 this.toHide = $([]);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
470 this.currentElements = $([]);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
471 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
472
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
473 prepareForm: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
474 this.reset();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
475 this.toHide = this.errors().add( this.containers );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
476 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
477
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
478 prepareElement: function( element ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
479 this.reset();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
480 this.toHide = this.errorsFor(element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
481 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
482
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
483 check: function( element ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
484 element = this.clean( element );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
485
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
486 // if radio/checkbox, validate first element in group instead
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
487 if (this.checkable(element)) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
488 element = this.findByName( element.name )[0];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
489 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
490
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
491 var rules = $(element).rules();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
492 var dependencyMismatch = false;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
493 for( method in rules ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
494 var rule = { method: method, parameters: rules[method] };
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
495 try {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
496 var result = $.validator.methods[method].call( this, element.value.replace(/\r/g, ""), element, rule.parameters );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
497
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
498 // if a method indicates that the field is optional and therefore valid,
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
499 // don't mark it as valid when there are no other rules
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
500 if ( result == "dependency-mismatch" ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
501 dependencyMismatch = true;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
502 continue;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
503 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
504 dependencyMismatch = false;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
505
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
506 if ( result == "pending" ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
507 this.toHide = this.toHide.not( this.errorsFor(element) );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
508 return;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
509 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
510
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
511 if( !result ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
512 this.formatAndAdd( element, rule );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
513 return false;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
514 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
515 } catch(e) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
516 this.settings.debug && window.console && console.log("exception occured when checking element " + element.id
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
517 + ", check the '" + rule.method + "' method", e);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
518 throw e;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
519 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
520 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
521 if (dependencyMismatch)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
522 return;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
523 if ( this.objectLength(rules) )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
524 this.successList.push(element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
525 return true;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
526 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
527
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
528 // return the custom message for the given element and validation method
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
529 // specified in the element's "messages" metadata
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
530 customMetaMessage: function(element, method) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
531 if (!$.metadata)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
532 return;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
533
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
534 var meta = this.settings.meta
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
535 ? $(element).metadata()[this.settings.meta]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
536 : $(element).metadata();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
537
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
538 return meta && meta.messages && meta.messages[method];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
539 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
540
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
541 // return the custom message for the given element name and validation method
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
542 customMessage: function( name, method ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
543 var m = this.settings.messages[name];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
544 return m && (m.constructor == String
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
545 ? m
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
546 : m[method]);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
547 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
548
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
549 // return the first defined argument, allowing empty strings
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
550 findDefined: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
551 for(var i = 0; i < arguments.length; i++) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
552 if (arguments[i] !== undefined)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
553 return arguments[i];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
554 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
555 return undefined;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
556 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
557
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
558 defaultMessage: function( element, method) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
559 return this.findDefined(
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
560 this.customMessage( element.name, method ),
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
561 this.customMetaMessage( element, method ),
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
562 // title is never undefined, so handle empty string as undefined
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
563 !this.settings.ignoreTitle && element.title || undefined,
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
564 $.validator.messages[method],
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
565 "<strong>Warning: No message defined for " + element.name + "</strong>"
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
566 );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
567 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
568
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
569 formatAndAdd: function( element, rule ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
570 var message = this.defaultMessage( element, rule.method ),
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
571 theregex = /\$?\{(\d+)\}/g;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
572 if ( typeof message == "function" ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
573 message = message.call(this, rule.parameters, element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
574 } else if (theregex.test(message)) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
575 message = jQuery.format(message.replace(theregex, '{$1}'), rule.parameters);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
576 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
577 this.errorList.push({
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
578 message: message,
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
579 element: element
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
580 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
581
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
582 this.errorMap[element.name] = message;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
583 this.submitted[element.name] = message;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
584 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
585
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
586 addWrapper: function(toToggle) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
587 if ( this.settings.wrapper )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
588 toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
589 return toToggle;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
590 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
591
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
592 defaultShowErrors: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
593 for ( var i = 0; this.errorList[i]; i++ ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
594 var error = this.errorList[i];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
595 this.settings.highlight && this.settings.highlight.call( this, error.element, this.settings.errorClass, this.settings.validClass );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
596 this.showLabel( error.element, error.message );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
597 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
598 if( this.errorList.length ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
599 this.toShow = this.toShow.add( this.containers );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
600 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
601 if (this.settings.success) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
602 for ( var i = 0; this.successList[i]; i++ ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
603 this.showLabel( this.successList[i] );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
604 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
605 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
606 if (this.settings.unhighlight) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
607 for ( var i = 0, elements = this.validElements(); elements[i]; i++ ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
608 this.settings.unhighlight.call( this, elements[i], this.settings.errorClass, this.settings.validClass );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
609 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
610 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
611 this.toHide = this.toHide.not( this.toShow );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
612 this.hideErrors();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
613 this.addWrapper( this.toShow ).show();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
614 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
615
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
616 validElements: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
617 return this.currentElements.not(this.invalidElements());
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
618 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
619
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
620 invalidElements: function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
621 return $(this.errorList).map(function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
622 return this.element;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
623 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
624 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
625
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
626 showLabel: function(element, message) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
627 var label = this.errorsFor( element );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
628 if ( label.length ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
629 // refresh error/success class
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
630 label.removeClass().addClass( this.settings.errorClass );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
631
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
632 // check if we have a generated label, replace the message then
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
633 label.attr("generated") && label.html(message);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
634 } else {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
635 // create label
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
636 label = $("<" + this.settings.errorElement + "/>")
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
637 .attr({"for": this.idOrName(element), generated: true})
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
638 .addClass(this.settings.errorClass)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
639 .html(message || "");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
640 if ( this.settings.wrapper ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
641 // make sure the element is visible, even in IE
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
642 // actually showing the wrapped element is handled elsewhere
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
643 label = label.hide().show().wrap("<" + this.settings.wrapper + "/>").parent();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
644 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
645 if ( !this.labelContainer.append(label).length )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
646 this.settings.errorPlacement
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
647 ? this.settings.errorPlacement(label, $(element) )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
648 : label.insertAfter(element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
649 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
650 if ( !message && this.settings.success ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
651 label.text("");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
652 typeof this.settings.success == "string"
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
653 ? label.addClass( this.settings.success )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
654 : this.settings.success( label );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
655 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
656 this.toShow = this.toShow.add(label);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
657 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
658
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
659 errorsFor: function(element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
660 var name = this.idOrName(element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
661 return this.errors().filter(function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
662 return $(this).attr('for') == name;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
663 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
664 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
665
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
666 idOrName: function(element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
667 return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
668 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
669
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
670 checkable: function( element ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
671 return /radio|checkbox/i.test(element.type);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
672 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
673
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
674 findByName: function( name ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
675 // select by name and filter by form for performance over form.find("[name=...]")
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
676 var form = this.currentForm;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
677 return $(document.getElementsByName(name)).map(function(index, element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
678 return element.form == form && element.name == name && element || null;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
679 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
680 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
681
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
682 getLength: function(value, element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
683 switch( element.nodeName.toLowerCase() ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
684 case 'select':
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
685 return $("option:selected", element).length;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
686 case 'input':
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
687 if( this.checkable( element) )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
688 return this.findByName(element.name).filter(':checked').length;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
689 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
690 return value.length;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
691 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
692
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
693 depend: function(param, element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
694 return this.dependTypes[typeof param]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
695 ? this.dependTypes[typeof param](param, element)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
696 : true;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
697 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
698
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
699 dependTypes: {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
700 "boolean": function(param, element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
701 return param;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
702 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
703 "string": function(param, element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
704 return !!$(param, element.form).length;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
705 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
706 "function": function(param, element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
707 return param(element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
708 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
709 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
710
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
711 optional: function(element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
712 return !$.validator.methods.required.call(this, $.trim(element.value), element) && "dependency-mismatch";
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
713 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
714
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
715 startRequest: function(element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
716 if (!this.pending[element.name]) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
717 this.pendingRequest++;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
718 this.pending[element.name] = true;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
719 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
720 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
721
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
722 stopRequest: function(element, valid) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
723 this.pendingRequest--;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
724 // sometimes synchronization fails, make sure pendingRequest is never < 0
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
725 if (this.pendingRequest < 0)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
726 this.pendingRequest = 0;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
727 delete this.pending[element.name];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
728 if ( valid && this.pendingRequest == 0 && this.formSubmitted && this.form() ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
729 $(this.currentForm).submit();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
730 this.formSubmitted = false;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
731 } else if (!valid && this.pendingRequest == 0 && this.formSubmitted) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
732 $(this.currentForm).triggerHandler("invalid-form", [this]);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
733 this.formSubmitted = false;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
734 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
735 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
736
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
737 previousValue: function(element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
738 return $.data(element, "previousValue") || $.data(element, "previousValue", {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
739 old: null,
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
740 valid: true,
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
741 message: this.defaultMessage( element, "remote" )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
742 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
743 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
744
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
745 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
746
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
747 classRuleSettings: {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
748 required: {required: true},
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
749 email: {email: true},
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
750 url: {url: true},
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
751 date: {date: true},
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
752 dateISO: {dateISO: true},
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
753 dateDE: {dateDE: true},
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
754 number: {number: true},
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
755 numberDE: {numberDE: true},
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
756 digits: {digits: true},
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
757 creditcard: {creditcard: true}
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
758 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
759
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
760 addClassRules: function(className, rules) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
761 className.constructor == String ?
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
762 this.classRuleSettings[className] = rules :
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
763 $.extend(this.classRuleSettings, className);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
764 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
765
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
766 classRules: function(element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
767 var rules = {};
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
768 var classes = $(element).attr('class');
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
769 classes && $.each(classes.split(' '), function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
770 if (this in $.validator.classRuleSettings) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
771 $.extend(rules, $.validator.classRuleSettings[this]);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
772 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
773 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
774 return rules;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
775 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
776
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
777 attributeRules: function(element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
778 var rules = {};
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
779 var $element = $(element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
780
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
781 for (method in $.validator.methods) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
782 var value = $element.attr(method);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
783 if (value) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
784 rules[method] = value;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
785 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
786 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
787
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
788 // maxlength may be returned as -1, 2147483647 (IE) and 524288 (safari) for text inputs
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
789 if (rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength)) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
790 delete rules.maxlength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
791 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
792
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
793 return rules;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
794 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
795
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
796 metadataRules: function(element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
797 if (!$.metadata) return {};
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
798
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
799 var meta = $.data(element.form, 'validator').settings.meta;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
800 return meta ?
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
801 $(element).metadata()[meta] :
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
802 $(element).metadata();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
803 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
804
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
805 staticRules: function(element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
806 var rules = {};
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
807 var validator = $.data(element.form, 'validator');
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
808 if (validator.settings.rules) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
809 rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {};
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
810 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
811 return rules;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
812 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
813
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
814 normalizeRules: function(rules, element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
815 // handle dependency check
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
816 $.each(rules, function(prop, val) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
817 // ignore rule when param is explicitly false, eg. required:false
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
818 if (val === false) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
819 delete rules[prop];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
820 return;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
821 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
822 if (val.param || val.depends) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
823 var keepRule = true;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
824 switch (typeof val.depends) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
825 case "string":
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
826 keepRule = !!$(val.depends, element.form).length;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
827 break;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
828 case "function":
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
829 keepRule = val.depends.call(element, element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
830 break;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
831 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
832 if (keepRule) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
833 rules[prop] = val.param !== undefined ? val.param : true;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
834 } else {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
835 delete rules[prop];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
836 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
837 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
838 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
839
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
840 // evaluate parameters
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
841 $.each(rules, function(rule, parameter) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
842 rules[rule] = $.isFunction(parameter) ? parameter(element) : parameter;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
843 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
844
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
845 // clean number parameters
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
846 $.each(['minlength', 'maxlength', 'min', 'max'], function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
847 if (rules[this]) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
848 rules[this] = Number(rules[this]);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
849 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
850 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
851 $.each(['rangelength', 'range'], function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
852 if (rules[this]) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
853 rules[this] = [Number(rules[this][0]), Number(rules[this][1])];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
854 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
855 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
856
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
857 if ($.validator.autoCreateRanges) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
858 // auto-create ranges
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
859 if (rules.min && rules.max) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
860 rules.range = [rules.min, rules.max];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
861 delete rules.min;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
862 delete rules.max;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
863 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
864 if (rules.minlength && rules.maxlength) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
865 rules.rangelength = [rules.minlength, rules.maxlength];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
866 delete rules.minlength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
867 delete rules.maxlength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
868 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
869 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
870
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
871 // To support custom messages in metadata ignore rule methods titled "messages"
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
872 if (rules.messages) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
873 delete rules.messages;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
874 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
875
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
876 return rules;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
877 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
878
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
879 // Converts a simple string to a {string: true} rule, e.g., "required" to {required:true}
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
880 normalizeRule: function(data) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
881 if( typeof data == "string" ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
882 var transformed = {};
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
883 $.each(data.split(/\s/), function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
884 transformed[this] = true;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
885 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
886 data = transformed;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
887 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
888 return data;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
889 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
890
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
891 // http://docs.jquery.com/Plugins/Validation/Validator/addMethod
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
892 addMethod: function(name, method, message) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
893 $.validator.methods[name] = method;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
894 $.validator.messages[name] = message != undefined ? message : $.validator.messages[name];
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
895 if (method.length < 3) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
896 $.validator.addClassRules(name, $.validator.normalizeRule(name));
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
897 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
898 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
899
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
900 methods: {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
901
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
902 // http://docs.jquery.com/Plugins/Validation/Methods/required
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
903 required: function(value, element, param) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
904 // check if dependency is met
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
905 if ( !this.depend(param, element) )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
906 return "dependency-mismatch";
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
907 switch( element.nodeName.toLowerCase() ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
908 case 'select':
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
909 // could be an array for select-multiple or a string, both are fine this way
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
910 var val = $(element).val();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
911 return val && val.length > 0;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
912 case 'input':
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
913 if ( this.checkable(element) )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
914 return this.getLength(value, element) > 0;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
915 default:
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
916 return $.trim(value).length > 0;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
917 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
918 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
919
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
920 // http://docs.jquery.com/Plugins/Validation/Methods/remote
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
921 remote: function(value, element, param) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
922 if ( this.optional(element) )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
923 return "dependency-mismatch";
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
924
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
925 var previous = this.previousValue(element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
926 if (!this.settings.messages[element.name] )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
927 this.settings.messages[element.name] = {};
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
928 previous.originalMessage = this.settings.messages[element.name].remote;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
929 this.settings.messages[element.name].remote = previous.message;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
930
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
931 param = typeof param == "string" && {url:param} || param;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
932
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
933 if ( previous.old !== value ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
934 previous.old = value;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
935 var validator = this;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
936 this.startRequest(element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
937 var data = {};
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
938 data[element.name] = value;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
939 $.ajax($.extend(true, {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
940 url: param,
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
941 mode: "abort",
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
942 port: "validate" + element.name,
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
943 dataType: "json",
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
944 data: data,
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
945 success: function(response) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
946 validator.settings.messages[element.name].remote = previous.originalMessage;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
947 var valid = response === true;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
948 if ( valid ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
949 var submitted = validator.formSubmitted;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
950 validator.prepareElement(element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
951 validator.formSubmitted = submitted;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
952 validator.successList.push(element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
953 validator.showErrors();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
954 } else {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
955 var errors = {};
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
956 var message = (previous.message = response || validator.defaultMessage( element, "remote" ));
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
957 errors[element.name] = $.isFunction(message) ? message(value) : message;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
958 validator.showErrors(errors);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
959 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
960 previous.valid = valid;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
961 validator.stopRequest(element, valid);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
962 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
963 }, param));
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
964 return "pending";
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
965 } else if( this.pending[element.name] ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
966 return "pending";
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
967 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
968 return previous.valid;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
969 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
970
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
971 // http://docs.jquery.com/Plugins/Validation/Methods/minlength
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
972 minlength: function(value, element, param) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
973 return this.optional(element) || this.getLength($.trim(value), element) >= param;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
974 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
975
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
976 // http://docs.jquery.com/Plugins/Validation/Methods/maxlength
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
977 maxlength: function(value, element, param) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
978 return this.optional(element) || this.getLength($.trim(value), element) <= param;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
979 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
980
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
981 // http://docs.jquery.com/Plugins/Validation/Methods/rangelength
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
982 rangelength: function(value, element, param) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
983 var length = this.getLength($.trim(value), element);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
984 return this.optional(element) || ( length >= param[0] && length <= param[1] );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
985 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
986
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
987 // http://docs.jquery.com/Plugins/Validation/Methods/min
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
988 min: function( value, element, param ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
989 return this.optional(element) || value >= param;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
990 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
991
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
992 // http://docs.jquery.com/Plugins/Validation/Methods/max
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
993 max: function( value, element, param ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
994 return this.optional(element) || value <= param;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
995 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
996
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
997 // http://docs.jquery.com/Plugins/Validation/Methods/range
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
998 range: function( value, element, param ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
999 return this.optional(element) || ( value >= param[0] && value <= param[1] );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1000 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1001
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1002 // http://docs.jquery.com/Plugins/Validation/Methods/email
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1003 email: function(value, element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1004 // contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1005 return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1006 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1007
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1008 // http://docs.jquery.com/Plugins/Validation/Methods/url
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1009 url: function(value, element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1010 // contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1011 return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1012 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1013
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1014 // http://docs.jquery.com/Plugins/Validation/Methods/date
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1015 date: function(value, element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1016 return this.optional(element) || !/Invalid|NaN/.test(new Date(value));
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1017 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1018
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1019 // http://docs.jquery.com/Plugins/Validation/Methods/dateISO
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1020 dateISO: function(value, element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1021 return this.optional(element) || /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(value);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1022 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1023
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1024 // http://docs.jquery.com/Plugins/Validation/Methods/number
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1025 number: function(value, element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1026 return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(value);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1027 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1028
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1029 // http://docs.jquery.com/Plugins/Validation/Methods/digits
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1030 digits: function(value, element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1031 return this.optional(element) || /^\d+$/.test(value);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1032 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1033
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1034 // http://docs.jquery.com/Plugins/Validation/Methods/creditcard
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1035 // based on http://en.wikipedia.org/wiki/Luhn
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1036 creditcard: function(value, element) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1037 if ( this.optional(element) )
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1038 return "dependency-mismatch";
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1039 // accept only digits and dashes
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1040 if (/[^0-9-]+/.test(value))
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1041 return false;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1042 var nCheck = 0,
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1043 nDigit = 0,
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1044 bEven = false;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1045
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1046 value = value.replace(/\D/g, "");
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1047
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1048 for (var n = value.length - 1; n >= 0; n--) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1049 var cDigit = value.charAt(n);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1050 var nDigit = parseInt(cDigit, 10);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1051 if (bEven) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1052 if ((nDigit *= 2) > 9)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1053 nDigit -= 9;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1054 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1055 nCheck += nDigit;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1056 bEven = !bEven;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1057 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1058
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1059 return (nCheck % 10) == 0;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1060 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1061
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1062 // http://docs.jquery.com/Plugins/Validation/Methods/accept
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1063 accept: function(value, element, param) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1064 param = typeof param == "string" ? param.replace(/,/g, '|') : "png|jpe?g|gif";
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1065 return this.optional(element) || value.match(new RegExp(".(" + param + ")$", "i"));
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1066 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1067
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1068 // http://docs.jquery.com/Plugins/Validation/Methods/equalTo
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1069 equalTo: function(value, element, param) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1070 // bind to the blur event of the target in order to revalidate whenever the target field is updated
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1071 // TODO find a way to bind the event just once, avoiding the unbind-rebind overhead
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1072 var target = $(param).unbind(".validate-equalTo").bind("blur.validate-equalTo", function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1073 $(element).valid();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1074 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1075 return value == target.val();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1076 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1077
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1078 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1079
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1080 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1081
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1082 // deprecated, use $.validator.format instead
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1083 $.format = $.validator.format;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1084
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1085 })(jQuery);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1086
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1087 // ajax mode: abort
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1088 // usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1089 // if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1090 ;(function($) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1091 var ajax = $.ajax;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1092 var pendingRequests = {};
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1093 $.ajax = function(settings) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1094 // create settings for compatibility with ajaxSetup
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1095 settings = $.extend(settings, $.extend({}, $.ajaxSettings, settings));
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1096 var port = settings.port;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1097 if (settings.mode == "abort") {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1098 if ( pendingRequests[port] ) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1099 pendingRequests[port].abort();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1100 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1101 return (pendingRequests[port] = ajax.apply(this, arguments));
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1102 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1103 return ajax.apply(this, arguments);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1104 };
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1105 })(jQuery);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1106
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1107 // provides cross-browser focusin and focusout events
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1108 // IE has native support, in other browsers, use event caputuring (neither bubbles)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1109
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1110 // provides delegate(type: String, delegate: Selector, handler: Callback) plugin for easier event delegation
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1111 // handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1112 ;(function($) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1113 // only implement if not provided by jQuery core (since 1.4)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1114 // TODO verify if jQuery 1.4's implementation is compatible with older jQuery special-event APIs
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1115 if (!jQuery.event.special.focusin && !jQuery.event.special.focusout && document.addEventListener) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1116 $.each({
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1117 focus: 'focusin',
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1118 blur: 'focusout'
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1119 }, function( original, fix ){
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1120 $.event.special[fix] = {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1121 setup:function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1122 this.addEventListener( original, handler, true );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1123 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1124 teardown:function() {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1125 this.removeEventListener( original, handler, true );
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1126 },
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1127 handler: function(e) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1128 arguments[0] = $.event.fix(e);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1129 arguments[0].type = fix;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1130 return $.event.handle.apply(this, arguments);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1131 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1132 };
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1133 function handler(e) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1134 e = $.event.fix(e);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1135 e.type = fix;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1136 return $.event.handle.call(this, e);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1137 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1138 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1139 };
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1140 $.extend($.fn, {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1141 validateDelegate: function(delegate, type, handler) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1142 return this.bind(type, function(event) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1143 var target = $(event.target);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1144 if (target.is(delegate)) {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1145 return handler.apply(target, arguments);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1146 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1147 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1148 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1149 });
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
1150 })(jQuery);