From 6894e3ecaefc68627e8f08812bc9224214c31c95 Mon Sep 17 00:00:00 2001 From: Brad Gessler Date: Tue, 13 Feb 2024 14:43:43 -0800 Subject: [PATCH] Add radio inputs --- README.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4a2c4bd..aecf624 100644 --- a/README.md +++ b/README.md @@ -138,15 +138,18 @@ class SignupForm < ApplicationForm [true, "Yes"], # [false, "No"], # "Hell no", # - nil # + nil, # + WebSources.select(:id, :name) + # Iterates through the `WebSources` scope and generates options + # where `id` is the value and `name` is the label. ) end div do render field(:source).label { "How did you hear about us?" } render field(:source).select do |s| - # Pretend WebSources is an ActiveRecord scope with a "Social" category that has "Facebook, X, etc" - # and a "Search" category with "AltaVista, Yahoo, etc." + # Pretend WebSources is an ActiveRecord scope with a "Social" category that + # has "Facebook, X, etc" and a "Search" category with "AltaVista, Yahoo, etc." WebSources.select(:id, :name).group_by(:category) do |category, sources| s.optgroup(label: category) do s.options(sources) @@ -155,6 +158,52 @@ class SignupForm < ApplicationForm end end + div do + render field(:channel).label { "How should we annoy you?" } + # Time for radio buttons! Pass arguments into the `radio` method and each one is + # an option with a label. A hidden input gets rendered that's the current value of the + # `channel` field. + render field(:channel).radio( + # + ["email", "Email"], + # + ["phone", "Phone"], + # + ["mail", "Mail"], + # + "House Visit", + # + nil, + # + # m + TimesOfDay.select(:id, :name) + # Iterates through TimesOfDay scope and generates options where `id` is the value + # and `name` is the label. + ) + end + + div do + render field(:time).label { "When should we interupt you?" } + # Pass a block into the `radio` method and each one is an option with a label. + render field(:time).radio do |r| + TimesOfDay.select(:id, :name) do |time| + r.label do + span(class: "font-bold") { time.name } + r.input(value: time.id) + end + end + end + end + div do render field(:agreement).label { "Check this box if you agree to give us your first born child" } render field(:agreement).checkbox(checked: true)