Skip to content

Commit e413808

Browse files
sparky672staabm
authored andcommitted
Entries: Changed generic form selector
Some examples on this page are using `$(".selector").validate()` and others are using `$("#myform").validate()`. Using `$(".selector")` implies that `.validate()` can be directly attached to a class selector where, if this is done without using an `.each()`, it would only be attached to the first instance of this class. The `$(".selector")` should be changed into `$("#myform")` on the entire page for better consistency and less confusion. I think `$("#myform")` is more appropriate since the `.validate()` method should only be attached to a selector that represents a single `form` element. Closes #24.
1 parent 6fb08fd commit e413808

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

entries/validate.xml

+23-23
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
Enables debug mode. If true, the form is not submitted and certain errors are displayed on the console (will check if a <code>window.console</code> property exists). Try to enable when a form is just submitted instead of validation stopping the submit.
1717
<p><strong>Example</strong>: Prevents the form from submitting and tries to help setting up the validation with warnings about missing methods and other debug messages.</p>
1818
<pre><code>
19-
$(".selector").validate({
19+
$("#myform").validate({
2020
debug: true
2121
});
2222
</code></pre>
@@ -28,15 +28,15 @@
2828
Callback for handling the actual submit when the form is valid. Gets the form as the only argument. Replaces the default submit. The right place to <a href="http://www.malsup.com/jquery/form/#api">submit a form via Ajax</a> after it is validated.
2929
<p><strong>Example</strong>: Submits the form via Ajax when valid.</p>
3030
<pre><code>
31-
$(".selector").validate({
31+
$("#myform").validate({
3232
submitHandler: function(form) {
3333
$(form).ajaxSubmit();
3434
}
3535
});
3636
</code></pre>
3737
<p><strong>Example</strong>: Use submitHandler to process something and then using the default submit. Note that "form" refers to a DOM element, this way the validation isn't triggered again.</p>
3838
<pre><code>
39-
$(".selector").validate({
39+
$("#myform").validate({
4040
submitHandler: function(form) {
4141
// do other things for a valid form
4242
form.submit();
@@ -58,7 +58,7 @@
5858
Callback for custom code when an invalid form is submitted. Called with an event object as the first argument, and the validator as the second.
5959
<p><strong>Example</strong>: Displays a message above the form, indicating how many fields are invalid when the user tries to submit an invalid form.</p>
6060
<pre><code>
61-
$(".selector").validate({
61+
$("#myform").validate({
6262
invalidHandler: function(event, validator) {
6363
// 'this' refers to the form
6464
var errors = validator.numberOfInvalids();
@@ -101,7 +101,7 @@
101101
Key/value pairs defining custom rules. Key is the name of an element (or a group of checkboxes/radio buttons), value is an object consisting of rule/parameter pairs or a plain String. Can be combined with class/attribute/data rules. Each rule can be specified as having a depends-property to apply the rule only in certain conditions. See the second example below for details.
102102
<p><strong>Example</strong>: Specifies a name element as required and an email element as required (using the shortcut for a single rule) and a valid email address (using another object literal).</p>
103103
<pre><code>
104-
$(".selector").validate({
104+
$("#myform").validate({
105105
rules: {
106106
// simple rule, converted to {required:true}
107107
name: "required",
@@ -115,7 +115,7 @@
115115
</code></pre>
116116
<p><strong>Example</strong>: Specifies a contact element as required and as email address, the latter depending on a checkbox being checked for contact via email.</p>
117117
<pre><code>
118-
$(".selector").validate({
118+
$("#myform").validate({
119119
rules: {
120120
contact: {
121121
required: true,
@@ -130,7 +130,7 @@
130130
</code></pre>
131131
<p><strong>Example</strong>: Configure a rule that requires a parameter, along with a <code>depends</code> callback.</p>
132132
<pre><code>
133-
$(".selector").validate({
133+
$("#myform").validate({
134134
rules: {
135135
// at least 15€ when bonus material is included
136136
pay_what_you_want: {
@@ -154,7 +154,7 @@
154154
Key/value pairs defining custom messages. Key is the name of an element, value the message to display for that element. Instead of a plain message, another map with specific messages for each rule can be used. Overrides the title attribute of an element or the default message for the method (in that order). Each message can be a String or a Callback. The callback is called in the scope of the validator, with the rule's parameters as the first argument and the element as the second, and must return a String to display as the message.
155155
<p><strong>Example</strong>: Specifies a name element as required and an email element as required and a valid email address. A single message is specified for the name element, and two messages for email.</p>
156156
<pre><code>
157-
$(".selector").validate({
157+
$$("#myform").validate({
158158
rules: {
159159
name: "required",
160160
email: {
@@ -173,7 +173,7 @@
173173
</code></pre>
174174
<p><strong>Example</strong>: Validates the name-field as required and having at least two characters. Provides a callback message using jQuery.validator.format to avoid having to specify the parameter in two places.</p>
175175
<pre><code>
176-
$(".selector").validate({
176+
$("#myform").validate({
177177
rules: {
178178
name: {
179179
required: true,
@@ -219,7 +219,7 @@
219219
<p>A boolean true is not a valid value.</p>
220220
<p><strong>Example</strong>: Disables onsubmit validation, allowing the user to submit whatever he wants, while still validating on keyup/blur/click events (if not specified otherwise).</p>
221221
<pre><code>
222-
$(".selector").validate({
222+
$("#myform").validate({
223223
onsubmit: false
224224
});
225225
</code></pre>
@@ -233,7 +233,7 @@
233233
<p>A boolean true is not a valid value.</p>
234234
<p><strong>Example</strong>: Disables onblur validation.</p>
235235
<pre><code>
236-
$(".selector").validate({
236+
$("#myform").validate({
237237
onfocusout: false
238238
});
239239
</code></pre>
@@ -255,7 +255,7 @@
255255
<p>A boolean true is not a valid value.</p>
256256
<p><strong>Example</strong>: Disables onkeyup validation.</p>
257257
<pre><code>
258-
$(".selector").validate({
258+
$("#myform").validate({
259259
onkeyup: false
260260
});
261261
</code></pre>
@@ -277,7 +277,7 @@
277277
<p>A boolean true is not a valid value.</p>
278278
<p><strong>Example</strong>: Disables onclick validation of checkboxes and radio buttons.</p>
279279
<pre><code>
280-
$(".selector").validate({
280+
$("#myform").validate({
281281
onclick: false
282282
});
283283
</code></pre>
@@ -297,7 +297,7 @@
297297
Focus the last active or first invalid element on submit via validator.focusInvalid(). The last active element is the one that had focus when the form was submitted, avoiding stealing its focus. If there was no element focused, the first one in the form gets it, unless this option is turned off.
298298
<p><strong>Example</strong>: Disables focusing of invalid elements.</p>
299299
<pre><code>
300-
$(".selector").validate({
300+
$("#myform").validate({
301301
focusInvalid: false
302302
});
303303
</code></pre>
@@ -309,7 +309,7 @@
309309
If enabled, removes the errorClass from the invalid elements and hides all error messages whenever the element is focused. Avoid combination with focusInvalid.
310310
<p><strong>Example</strong>: Enables cleanup when focusing elements, removing the error class and hiding error messages when an element is focused.</p>
311311
<pre><code>
312-
$(".selector").validate({
312+
$("#myform").validate({
313313
focusCleanup: true
314314
});
315315
</code></pre>
@@ -321,7 +321,7 @@
321321
Use this class to create error labels, to look for existing error labels and to add it to invalid elements.
322322
<p><strong>Example</strong>: Sets the error class to "invalid".</p>
323323
<pre><code>
324-
$(".selector").validate({
324+
$("#myform").validate({
325325
errorClass: "invalid"
326326
});
327327
</code></pre>
@@ -333,7 +333,7 @@
333333
This class is added to an element after it was validated and considered valid.
334334
<p><strong>Example</strong>: Sets the valid class to "success".</p>
335335
<pre><code>
336-
$(".selector").validate({
336+
$("#myform").validate({
337337
validClass: "success"
338338
});
339339
</code></pre>
@@ -345,7 +345,7 @@
345345
Use this element type to create error messages and to look for existing error messages. The default, "label", has the advantage of creating a meaningful link between error message and invalid field using the for attribute (which is always used, regardless of element type).
346346
<p><strong>Example</strong>: Sets the error element to "em".</p>
347347
<pre><code>
348-
$(".selector").validate({
348+
$("#myform").validate({
349349
errorElement: "em"
350350
});
351351
</code></pre>
@@ -357,7 +357,7 @@
357357
Wrap error labels with the specified element. Useful in combination with errorLabelContainer to create a list of error messages.
358358
<p><strong>Example</strong>: Wrap each error element with a list item, useful when using an ordered or unordered list as the error container.</p>
359359
<pre><code>
360-
$(".selector").validate({
360+
$("#myform").validate({
361361
wrapper: "li"
362362
});
363363
</code></pre>
@@ -398,7 +398,7 @@
398398
A custom message display handler. Gets the map of errors as the first argument and an array of errors as the second, called in the context of the validator object. The arguments contain only those elements currently validated, which can be a single element when doing validation onblur/keyup. You can trigger (in addition to your own messages) the default behaviour by calling this.defaultShowErrors().
399399
<p><strong>Example</strong>: Update the number of invalid elements each time an error is displayed. Delegates to the default implementation for the actual error display.</p>
400400
<pre><code>
401-
$(".selector").validate({
401+
$("#myform").validate({
402402
showErrors: function(errorMap, errorList) {
403403
$("#summary").html("Your form contains "
404404
+ this.numberOfInvalids()
@@ -479,7 +479,7 @@
479479
How to highlight invalid fields. Override to decide which fields and how to highlight.
480480
<p><strong>Example</strong>: Highlights an invalid element by fading it out and in again.</p>
481481
<pre><code>
482-
$(".selector").validate({
482+
$("#myform").validate({
483483
highlight: function(element, errorClass) {
484484
$(element).fadeOut(function() {
485485
$(element).fadeIn();
@@ -489,7 +489,7 @@
489489
</code></pre>
490490
<p><strong>Example</strong>: Adds the error class to both the invalid element and its label</p>
491491
<pre><code>
492-
$(".selector").validate({
492+
$("#myform").validate({
493493
highlight: function(element, errorClass, validClass) {
494494
$(element).addClass(errorClass).removeClass(validClass);
495495
$(element.form).find("label[for=" + element.id + "]")
@@ -526,7 +526,7 @@
526526
Set to skip reading messages from the title attribute, helps to avoid issues with Google Toolbar; default is false for compability, the message-from-title is likely to be completely removed in a future release.
527527
<p><strong>Example</strong>: Configure the plugin to ignore title attributes on validated elements when looking for messages.</p>
528528
<pre><code>
529-
$(".selector").validate({
529+
$("#myform").validate({
530530
ignoreTitle: true
531531
});
532532
</code></pre>

0 commit comments

Comments
 (0)