You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[See the wiki](https://github.com/bcardarella/client_side_validations/wiki/Callbacks)
132
+
## Understanding the embedded `<script>` tag ##
133
133
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.
134
166
135
167
## Plugins ##
136
168
@@ -170,8 +202,7 @@ pull requests to specific branches rather than master.
170
202
171
203
Please make sure you include tests!
172
204
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.
175
206
176
207
Don't use tabs to indent, two spaces are the standard.
0 commit comments