Skip to content

Update reference.md #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pages/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ To achieve this, it is important that the plugin is actually deployed on website
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.

# Markup recommendations
Each input has a label associated with it: The for-attribute of the label refers to the id-attribute of the input.
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.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note sure we need to note it, but the id has to be unique across the whole document

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the id has to be unique across the whole document

Not sure exactly what you mean here. Of course any id must be unique to the page, but this plugin does not require an id on any element.

See: http://jsfiddle.net/L2eody0z/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know if it is obvious to anyone using the plugin that a id has to be unique. I am ok not noting that though

Copy link
Contributor Author

@sparky672 sparky672 Jul 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know if it is obvious to anyone using the plugin that a id has to be unique. I am ok not noting that though

My note about id was only carried over from existing documentation using very similar wording...

Existing docs:

Usually name and id attributes should have the same value.

My proposed:

It's also a common practice to have 'id' and 'name' attributes with the same value...

Perhaps it's not clear enough this refers to id and name be the same as each other. Maybe this all should be removed since label, for, and id have nothing to do with how this plugin operates.


```html
<label for="firstname">Firstname</label>
<input id="firstname" name="fname">
```

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.

# Methods
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.

Expand Down