simple_form 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- data/README.rdoc +36 -36
- data/lib/simple_form/components/labels.rb +1 -1
- data/lib/simple_form/inputs/base.rb +1 -1
- data/lib/simple_form/version.rb +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -8,7 +8,7 @@ SimpleForm aims to be as flexible as possible while helping you with powerful co
|
|
8
8
|
|
9
9
|
Install the gem:
|
10
10
|
|
11
|
-
sudo gem install simple_form
|
11
|
+
sudo gem install simple_form
|
12
12
|
|
13
13
|
Run the generator:
|
14
14
|
|
@@ -26,9 +26,9 @@ SimpleForm was designed to be customized as you need to. Basically it's a stack
|
|
26
26
|
To start using SimpleForm you just have to use the helper it provides:
|
27
27
|
|
28
28
|
<% simple_form_for @user do |f| -%>
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
<%= f.input :username %>
|
30
|
+
<%= f.input :password %>
|
31
|
+
<%= f.button :submit %>
|
32
32
|
<% end -%>
|
33
33
|
|
34
34
|
This will generate an entire form with labels for user name and password as well, and render errors by default when you render the form with invalid data (after submitting for example).
|
@@ -36,37 +36,37 @@ This will generate an entire form with labels for user name and password as well
|
|
36
36
|
You can overwrite the default label by passing it to the input method, or even add a hint:
|
37
37
|
|
38
38
|
<% simple_form_for @user do |f| -%>
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
<%= f.input :username, :label => 'Your username please' %>
|
40
|
+
<%= f.input :password, :hint => 'No special characters.' %>
|
41
|
+
<%= f.button :submit %>
|
42
42
|
<% end -%>
|
43
43
|
|
44
44
|
You can also disable labels, hints or error or configure the html of any of them:
|
45
45
|
|
46
46
|
<% simple_form_for @user do |f| -%>
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
<%= f.input :username, :label_html => { :class => 'my_class' } %>
|
48
|
+
<%= f.input :password, :hint => false, :error_html => { :id => "password_error"} %>
|
49
|
+
<%= f.input :password_confirmation, :label => false %>
|
50
|
+
<%= f.button :submit %>
|
51
51
|
<% end -%>
|
52
52
|
|
53
53
|
By default all inputs are required, which means an * is prepended to the label, but you can disable it in any input you want:
|
54
54
|
|
55
55
|
<% simple_form_for @user do |f| -%>
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
<%= f.input :name, :required => false %>
|
57
|
+
<%= f.input :username %>
|
58
|
+
<%= f.input :password %>
|
59
|
+
<%= f.button :submit %>
|
60
60
|
<% end -%>
|
61
61
|
|
62
62
|
SimpleForm also lets you overwrite the default input type it creates:
|
63
63
|
|
64
64
|
<% simple_form_for @user do |f| -%>
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
65
|
+
<%= f.input :username %>
|
66
|
+
<%= f.input :password %>
|
67
|
+
<%= f.input :description, :as => :text %>
|
68
|
+
<%= f.input :accepts, :as => :radio %>
|
69
|
+
<%= f.button :submit %>
|
70
70
|
<% end -%>
|
71
71
|
|
72
72
|
So instead of a checkbox for the :accepts attribute, you'll have a pair of radio buttons with yes/no labels and a text area instead of a text field for the description. You can also render boolean attributes using :as => :select to show a dropdown.
|
@@ -74,11 +74,11 @@ So instead of a checkbox for the :accepts attribute, you'll have a pair of radio
|
|
74
74
|
SimpleForm also allows you using label, hint and error helpers it provides:
|
75
75
|
|
76
76
|
<% simple_form_for @user do |f| -%>
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
77
|
+
<%= f.label :username %>
|
78
|
+
<%= f.text_field :username %>
|
79
|
+
<%= f.error :username, :id => 'user_name_error' %>
|
80
|
+
<%= f.hint 'No special characters, please!' %>
|
81
|
+
<%= f.submit 'Save' %>
|
82
82
|
<% end -%>
|
83
83
|
|
84
84
|
Any extra option passed to label, hint or error will be rendered as html option.
|
@@ -88,9 +88,9 @@ Any extra option passed to label, hint or error will be rendered as html option.
|
|
88
88
|
And what if you want to create a select containing the age from 18 to 60 in your form? You can do it overriding the :collection option:
|
89
89
|
|
90
90
|
<% simple_form_for @user do |f| -%>
|
91
|
-
|
92
|
-
|
93
|
-
|
91
|
+
<%= f.input :user %>
|
92
|
+
<%= f.input :age, :collection => 18..60 %>
|
93
|
+
<%= f.button :submit %>
|
94
94
|
<% end -%>
|
95
95
|
|
96
96
|
Collections can be arrays or ranges, and when a :collection is given the :select input will be rendered by default, so we don't need to pass the :as => :select option. Other types of collection are :radio and :check_boxes. Those are added by SimpleForm to Rails set of form helpers (read Extra Helpers session below for more information).
|
@@ -121,12 +121,12 @@ The first step is to configure a wrapper tag:
|
|
121
121
|
|
122
122
|
SimpleForm.wrapper_tag = :p
|
123
123
|
|
124
|
-
And now, you don't need to wrap your f.input calls with
|
124
|
+
And now, you don't need to wrap your f.input calls with anymore:
|
125
125
|
|
126
126
|
<% simple_form_for @user do |f| -%>
|
127
127
|
<%= f.input :username %>
|
128
128
|
<%= f.input :password %>
|
129
|
-
|
129
|
+
<%= f.button :submit %>
|
130
130
|
<% end -%>
|
131
131
|
|
132
132
|
== Associations
|
@@ -149,10 +149,10 @@ To deal with associations, SimpleForm can generate select inputs or a series of
|
|
149
149
|
Now we have the user form:
|
150
150
|
|
151
151
|
<% simple_form_for @user do |f| -%>
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
152
|
+
<%= f.input :name %>
|
153
|
+
<%= f.association :company %>
|
154
|
+
<%= f.association :roles %>
|
155
|
+
<%= f.button :submit %>
|
156
156
|
<% end -%>
|
157
157
|
|
158
158
|
Simple enough right? This is going to render a :select input for choosing the :company, and another :select input with :multiple option for the :roles. You can of course change it, to use radios and check boxes as well:
|
@@ -178,8 +178,8 @@ The association helper just invokes input under the hood, so all options availab
|
|
178
178
|
All web forms need buttons, right? SimpleForm wraps them in the DSL, acting like a proxy:
|
179
179
|
|
180
180
|
<% simple_form_for @user do |f| -%>
|
181
|
-
|
182
|
-
|
181
|
+
<%= f.input :name %>
|
182
|
+
<%= f.button :submit %>
|
183
183
|
<% end -%>
|
184
184
|
|
185
185
|
The above will simply call submit. You choose to use it or not, it's just a question of taste.
|
data/lib/simple_form/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Jos\xC3\xA9 Valim"
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-02-
|
13
|
+
date: 2010-02-19 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|