4
4
[ ![ Dependency Status] ( https://gemnasium.com/bcardarella/client_side_validations.png?travis )] ( https://gemnasium.com/bcardarella/client_side_validations )
5
5
[ ![ Code Climate] ( https://codeclimate.com/badge.png )] ( https://codeclimate.com/github/bcardarella/client_side_validations )
6
6
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!
11
8
12
9
## Project Goals ##
13
10
@@ -52,15 +49,6 @@ If you are using Rails 3.1+ you'll need to use:
52
49
rails g client_side_validations:copy_assets
53
50
```
54
51
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
-
64
52
## Initializer ##
65
53
66
54
The initializer includes a commented out ` ActionView::Base.field_error_proc ` .
@@ -73,6 +61,73 @@ rendered validation error messages and the server side rendered
73
61
validation error messages please use what is in
74
62
` config/initializers/client_side_validations.rb `
75
63
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
+
76
131
## Client Side Validation Callbacks ##
77
132
[ See the wiki] ( https://github.com/bcardarella/client_side_validations/wiki/Callbacks )
78
133
@@ -82,10 +137,18 @@ validation error messages please use what is in
82
137
There is additional support for other ` ActiveModel ` based ORMs and other
83
138
Rails ` FormBuilders ` . Please see the [ Plugin wiki page] ( https://github.com/bcardarella/client_side_validations/wiki/Plugins )
84
139
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
+
85
146
## Authors ##
86
147
87
148
[ Brian Cardarella] ( http://twitter.com/bcardarella )
88
149
150
+ [ We are very thankful for the many contributors] ( https://github.com/bcardarella/client_side_validations/graphs/contributors )
151
+
89
152
## Versioning ##
90
153
91
154
This gem follows [ Semantic Versioning] ( http://semver.org )
0 commit comments