Skip to content

Commit 4127687

Browse files
sparky672staabm
authored andcommitted
Reference: clarified markup recommendations.
Clarified this section to reflect many questions on StackOverflow. It's a common mistake to leave out or duplicate the `name` attribute. It's also a common misconception that an `id` is needed at all for this plugin to work. Nowhere in the documentation is it explicitly stated that `name` attribute must be unique...only implied. Closes #25.
1 parent 049a8c1 commit 4127687

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pages/reference.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ To achieve this, it is important that the plugin is actually deployed on website
1010
The plugin can never replace serverside validation and doesn't intend to do so. Having both in place gives you the necessary security for your application, as well as improved usability.
1111

1212
# Markup recommendations
13-
Each input has a label associated with it: The for-attribute of the label refers to the id-attribute of the input.
13+
Mandated: A 'name' attribute is required for all input elements needing validation, and the plugin will not work without this. A 'name' attribute must also be unique to the form, as this is how the plugin keeps track of all input elements. However, each group of radio or checkbox elements will share the same 'name' since the value of this grouping represents a single piece of the form data.
14+
15+
Optionally: Each input can have a label associated with it, where the 'for' attribute of the label refers to the 'id' attribute of the input. It's also a common practice to have 'id' and 'name' attributes with the same value, although keep in mind that since this plugin does not use the 'id' attribute, this is not mandatory.
16+
1417
```html
1518
<label for="firstname">Firstname</label>
1619
<input id="firstname" name="fname">
1720
```
1821

19-
The name attribute is '''required''' for input elements, the validation plugin doesn't work without it. Usually name and id attributes should have the same value.
20-
2122
# Methods
2223
A validation method implements the logic to validate any element. Provided are a set of default validation methods, such as required. Apart from required itself and equalTo, all validation methods declare an element valid when it has no value at all. That way an email field is optional unless required is specified. You can specify an element input to contain a valid email address, or nothing at all. Use <a href="/jQuery.validator.addMethod/">jQuery.validator.addMethod</a> to implement custom methods.
2324

0 commit comments

Comments
 (0)