Skip to content

Commit d3fd32b

Browse files
committed
Updated README
1 parent b5bb3d8 commit d3fd32b

File tree

1 file changed

+76
-13
lines changed

1 file changed

+76
-13
lines changed

README.md

Lines changed: 76 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
[![Dependency Status](https://gemnasium.com/bcardarella/client_side_validations.png?travis)](https://gemnasium.com/bcardarella/client_side_validations)
55
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/bcardarella/client_side_validations)
66

7-
`ClientSideValidations` made easy for your Rails applications!
8-
9-
In addition to this README please checkout the [wiki](https://github.com/bcardarella/client_side_validations/wiki) and
10-
[ClientSideValidations GoogleGroup](http://groups.google.com/group/client_side_validations).
7+
`ClientSideValidations` made easy for your Rails v3.1+ applications!
118

129
## Project Goals ##
1310

@@ -52,15 +49,6 @@ If you are using Rails 3.1+ you'll need to use:
5249
rails g client_side_validations:copy_assets
5350
```
5451

55-
## Usage ##
56-
57-
The javascript file is served up in the asset pipeline. Add the
58-
following to your `app/assets/javascripts/application.js` file.
59-
60-
```javascript
61-
//= require rails.validations
62-
```
63-
6452
## Initializer ##
6553

6654
The initializer includes a commented out `ActionView::Base.field_error_proc`.
@@ -73,6 +61,73 @@ rendered validation error messages and the server side rendered
7361
validation error messages please use what is in
7462
`config/initializers/client_side_validations.rb`
7563

64+
## Usage ##
65+
66+
The javascript file is served up in the asset pipeline. Add the
67+
following to your `app/assets/javascripts/application.js` file.
68+
69+
```javascript
70+
//= require rails.validations
71+
```
72+
73+
In your `FormBuilder` you only need to enable validations:
74+
75+
```erb
76+
<%= form_for @user, :validate => true do |f| %>
77+
...
78+
```
79+
80+
That should be enough to get you going.
81+
82+
## Conditional Validators ##
83+
84+
By default conditional validators are not evaluated and passed to the client.
85+
We do this because the state model when the form is rendered is not necessarily the state
86+
of the model when the validations fire server-side. However, if you wish to override this behavior you can do so
87+
in the form. Given the following model:
88+
89+
```ruby
90+
class Person < ActiveRecord::Base
91+
validates :name, :email, :presence => true, :length => { :maximum => 10 }, :if => :can_validate?
92+
93+
def can_validate
94+
true
95+
end
96+
end
97+
```
98+
99+
You can force in the form:
100+
101+
```erb
102+
<%= f.text_field :name, :validate => true %>
103+
```
104+
105+
Passing `:validate => true` will force all the validators for that attribute. If there are conditionals
106+
they are evaluated with the state of the model when rendering the form. You can also force
107+
individual validators:
108+
109+
```erb
110+
<%= f.text_field :name :validate => { :presence => true } %>
111+
```
112+
113+
In the above case only the `presence` validator will be passed to the client.
114+
115+
This is also the case with Procs (or any object that responds to `#call`
116+
117+
### Turning off validators ###
118+
119+
If you wish to skip validations on a given attribute force it to `false`:
120+
121+
```erb
122+
<%= f.text_field :name, :validate => false %>
123+
```
124+
125+
If you want to be more selective about the validation that is turned off you can simply do:
126+
127+
```erb
128+
<%= f.text_field :name, :validate => { :presence => false } %>
129+
```
130+
76131
## Client Side Validation Callbacks ##
77132
[See the wiki](https://github.com/bcardarella/client_side_validations/wiki/Callbacks)
78133

@@ -82,10 +137,18 @@ validation error messages please use what is in
82137
There is additional support for other `ActiveModel` based ORMs and other
83138
Rails `FormBuilders`. Please see the [Plugin wiki page](https://github.com/bcardarella/client_side_validations/wiki/Plugins)
84139

140+
* [SimpleForm](https://github.com/DockYard/client_side_validations-simple_form)
141+
* [Formtastic](https://github.com/DockYard/client_side_validations-formtastic)
142+
* [Mongoid](https://github.com/DockYard/client_side_validations-mongoid)
143+
* [MongoMapper](https://github.com/DockYard/client_side_validations-mongo_mapper)
144+
* [Turbolinks](https://github.com/DockYard/client_side_validations-turbolinks)
145+
85146
## Authors ##
86147

87148
[Brian Cardarella](http://twitter.com/bcardarella)
88149

150+
[We are very thankful for the many contributors](https://github.com/bcardarella/client_side_validations/graphs/contributors)
151+
89152
## Versioning ##
90153

91154
This gem follows [Semantic Versioning](http://semver.org)

0 commit comments

Comments
 (0)