Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 14fda64

Browse files
committedOct 8, 2012
Updated README
1 parent 0d7fa83 commit 14fda64

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed
 

‎README.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
validation.
1818
4. The client side validation error rendering should be
1919
indistinguishable from the server side validation error rendering.
20-
5. Wide browser compliancy. I've tested with IE8, seems to work OK.
20+
5. Wide browser compliancy.
2121
6. Work with any ActiveModel::Validations based model
2222
7. Validate nested fields
2323
8. Support custom validations
2424
9. Client side validation callbacks
25+
10. Plugin system to support additional FormBuilders, ORMs, etc...
2526

2627
## Install ##
2728

@@ -112,7 +113,7 @@ individual validators:
112113

113114
In the above case only the `presence` validator will be passed to the client.
114115

115-
This is also the case with Procs (or any object that responds to `#call`
116+
This is also the case with Procs, or any object that responds to `#call`
116117

117118
### Turning off validators ###
118119

@@ -128,9 +129,40 @@ If you want to be more selective about the validation that is turned off you can
128129
<%= f.text_field :name, :validate => { :presence => false } %>
129130
```
130131

131-
## Client Side Validation Callbacks ##
132-
[See the wiki](https://github.com/bcardarella/client_side_validations/wiki/Callbacks)
132+
## Understanding the embedded `<script>` tag ##
133133

134+
A rendered form with validations will always have a `<script>` appeneded
135+
directly after:
136+
137+
```html
138+
<script>//<![CDATA[if(window.ClientSideValidations==undefined)window.ClientSideValidations={};if(window.ClientSideValidations.forms==undefined)window.ClientSideValidations.forms={};window.ClientSideValidations.forms['new_person'] = {"type":"ActionView::Helpers::FormBuilder","input_tag":"<div class=\"field_with_errors\"><span id=\"input_tag\" /><label for=\"\" class=\"message\"></label></div>","label_tag":"<div class=\"field_with_errors\"><label id=\"label_tag\" /></div>","validators":{"person[name]":{"inclusion":[{"message":"is not included in the list","in":["Happy"]}]}}};//]]></script>
139+
```
140+
141+
This script registers a new form object on `ClientSideValidations.form`. The key is equal to the ID of the form that is rendered. The objects it contains will have different keys depending upon the `FormBuilder` being used. However, `type` and `validators` will always be present.
142+
143+
### `type` ###
144+
145+
This will always be equal to the class of the `FormBuilder` that did the rendering. The type will be used by the JavaScript to determine how to `add` and `remove` the error messages. If you create a new `FormBuilder` you will need to write your own handlers for adding and removing.
146+
147+
### `validators` ###
148+
149+
This object contains the validators for each of the inputs rendered on the `FormBuilder`. Each input is keyed to the `name` attribute and each containing validator could simply contain the error message itself or also specific options on how that validator should be run.
150+
151+
### Adding validators that aren't inputs ###
152+
153+
If you need to add more validators but don't want them rendered on the form immediately you can inject those validators with `FormBuilder#validate`:
154+
155+
```erb
156+
<%= form_for @user, :validate => true do |f| %>
157+
<p>
158+
<%= f.label :name %>
159+
<%= f.text_field :name %>
160+
</p>
161+
<%= f.validate :age, :bio %>
162+
...
163+
```
164+
165+
In the above example `age` and `bio` will not render as inputs on the form but their validators will be properly added to the `validators` object for use later. If you do intend to dynamically render these inputs later the `name` attributes on the inputs will have to match with the keys on the `validators` object, and the inputs will have to be enabled for client side validation.
134166

135167
## Plugins ##
136168

@@ -170,8 +202,7 @@ pull requests to specific branches rather than master.
170202

171203
Please make sure you include tests!
172204

173-
Unles Rails drops support for Ruby 1.8.7 we will continue to use the
174-
hash-rocket syntax. Please respect this.
205+
We *do not* use the Ruby 1.9 hash syntax, please respect this and use the hashrocket.
175206

176207
Don't use tabs to indent, two spaces are the standard.
177208

0 commit comments

Comments
 (0)
Please sign in to comment.