You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: entries/normalizer.xml
+60-8
Original file line number
Diff line number
Diff line change
@@ -8,10 +8,13 @@
8
8
</signature>
9
9
<desc>Prepares/transforms the elements value for validation.</desc>
10
10
<longdesc>
11
-
Note that this method:
12
-
<p>Doesn't change the elements' value, it only changes the value used for validation.</p>
13
-
<p>Gets the value passed as argument, and "this" within it references the corresponding DOMElement.</p>
14
-
<p>Needs to return a String value, otherwise it will throw a TypeError exception.</p>
11
+
<p>Transform the value of an element and the result for validation instead of the initial value. The normalizer can be defined global to all elements or local to only one element. With that said, the local normalizer will only run for the element for which it was defined. The global normalizer will run for all validated elements. This normalizer can be then overrided for each element, as needed, by attaching one to it. This way only the local one will run for that element, and the global one will run for others.</p>
12
+
<p>Note that this method:</p>
13
+
<ul>
14
+
<li><p>Doesn't change the elements' value, it only changes the value used for validation.</p></li>
15
+
<li><p>Gets the value passed as argument, and "this" within it references the corresponding <code>DOMElement</code>.</p></li>
16
+
<li><p>Needs to return a String value, otherwise it will throw a <code>TypeError</code> exception.</p></li>
17
+
</ul>
15
18
</longdesc>
16
19
<example>
17
20
<desc>Makes "field" required and use a normalizer to trim its value before validating</desc>
@@ -38,21 +41,67 @@ $( "#myform" ).validate( {
38
41
<input type="submit" value="Validate!">
39
42
]]></html>
40
43
</example>
41
-
<example>
42
-
<desc>Makes "url" required and use a normalizer to append 'http://', if not present, to the value of the "url" element before validating</desc>
44
+
<example>
45
+
<desc>Makes "url" required and use a normalizer to append 'http://', if not present, to the value of the "url" element before validating</desc>
46
+
<code><![CDATA[
47
+
$( "#myform" ).validate( {
48
+
rules: {
49
+
url_input: {
50
+
required: true,
51
+
url: true,
52
+
normalizer: function( value ) {
53
+
var url = value;
54
+
55
+
// Check if it doesn't start with http:// or https:// or ftp://
0 commit comments