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
Copy file name to clipboardExpand all lines: README.md
+49-9Lines changed: 49 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@
6
6
7
7
***Works beautifully with ERB.** Start using Superform in your existing Rails app without changing a single ERB template. All the power, zero migration pain.
8
8
9
-
***Concise field helpers.**`field(:publish_at).date`, `field(:email).email`, `field(:price).number` — intuitive methods that generate the right input types with proper validation.
9
+
***Concise field helpers.**`Field(:publish_at).date`, `Field(:email).email`, `field(:price).number` — intuitive methods that generate the right input types with proper validation.
10
10
11
11
***RESTful controller helpers** Superform's `save` and `save!` methods work exactly like ActiveRecord, making controller code predictable and Rails-like.
12
12
@@ -204,8 +204,8 @@ That looks like a LOT of code, and it is, but look at how easy it is to create f
204
204
# ./app/views/users/form.rb
205
205
classUsers::Form < Components::Form
206
206
defview_template(&)
207
-
labeled field(:name).input
208
-
labeled field(:email).input(type::email)
207
+
labeled Field(:name).input
208
+
labeled Field(:email).input(type::email)
209
209
210
210
submit "Sign up"
211
211
end
@@ -252,7 +252,7 @@ class AccountForm < Superform::Rails::Form
252
252
# Renders input with the name `account[members][0][permissions][]`,
253
253
# `account[members][1][permissions][]`, ...
254
254
render permission.label do
255
-
plain permisson.value.humanize
255
+
plain permission.value.humanize
256
256
render permission.checkbox
257
257
end
258
258
end
@@ -278,7 +278,7 @@ By default Superform namespaces a form based on the ActiveModel model name param
278
278
```ruby
279
279
classUserForm < Superform::Rails::Form
280
280
defview_template
281
-
render field(:email).input
281
+
render Field(:email).input
282
282
end
283
283
end
284
284
@@ -294,7 +294,7 @@ To customize the form namespace, like an ActiveRecord model nested within a modu
294
294
```ruby
295
295
classUserForm < Superform::Rails::Form
296
296
defview_template
297
-
render field(:email).input
297
+
render Field(:email).input
298
298
end
299
299
300
300
defkey
@@ -333,7 +333,10 @@ class SignupForm < Components::Form
333
333
end
334
334
end
335
335
336
-
# Let's get crazy with Selects. They can accept values as simple as 2 element arrays.
336
+
# Selects accept options as positional arguments. Each option can be:
337
+
# - A 2-element array: [value, label] renders <option value="value">label</option>
338
+
# - A single value: "text" renders <option value="text">text</option>
339
+
# - nil: renders an empty <option></option>
337
340
div do
338
341
Field(:contact).label { "Would you like us to spam you to death?" }
339
342
Field(:contact).select(
@@ -359,6 +362,43 @@ class SignupForm < Components::Form
359
362
end
360
363
end
361
364
365
+
# Pass nil as first argument to add a blank option at the start
0 commit comments