Hi i''m fairly new to ruby on rails and i''m creating a form using simple_form and in one bit i have radio buttons and say i have 3 buttons a,b,c so i want it to be if a is pressed then certain text fields show, and if b is pressed a different set of text fields show and similarly for c. Can anyone help me on this? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/8I3DBjMWlC0J. For more options, visit https://groups.google.com/groups/opt_out.
On 2 March 2013 16:20, NN Dodhia <aca10nnd-1V21x8GFL1deXsq7+8kxVA@public.gmane.org> wrote:> Hi i''m fairly new to ruby on rails and i''m creating a form using simple_form > and in one bit i have radio buttons and say i have 3 buttons a,b,c so i want > it to be if a is pressed then certain text fields show, and if b is pressed > a different set of text fields show and similarly for c. Can anyone help me > on this?You will probably want to use javascript for this, quite possibly jQuery. Have a look for some tutorials. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Mar 2, 2013, at 11:20 AM, NN Dodhia wrote:> Hi i''m fairly new to ruby on rails and i''m creating a form using simple_form and in one bit i have radio buttons and say i have 3 buttons a,b,c so i want it to be if a is pressed then certain text fields show, and if b is pressed a different set of text fields show and similarly for c. Can anyone help me on this?This is a JavaScript thing, not really specific to Rails. Coincidentally, I just made this sort of behavior in a Drupal site this morning. For this form, there were fields that made sense for postal mail subscribers that did not make sense for email subscribers. So I added a classname to each of the field wrappers -- either ''postal'' or ''email'' and used that to make my behavior work: http://jsfiddle.net/rk3vw/3/ This is using Prototype, I am sure you can use jQuery or "vanilla" JavaScript if that''s your thing. Walter> > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/8I3DBjMWlC0J. > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Maybe you can look at these screencasts and learn how to dynamically add form elements using javascript and then adapt it for your case as needed. http://railscasts.com/episodes/196-nested-model-form-part-1 http://railscasts.com/episodes/197-nested-model-form-part-2 http://railscasts.com/episodes/196-nested-model-form-revised On Sun, Mar 3, 2013 at 3:48 AM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> > On Mar 2, 2013, at 11:20 AM, NN Dodhia wrote: > > > Hi i''m fairly new to ruby on rails and i''m creating a form using > simple_form and in one bit i have radio buttons and say i have 3 buttons > a,b,c so i want it to be if a is pressed then certain text fields show, and > if b is pressed a different set of text fields show and similarly for c. > Can anyone help me on this? > > This is a JavaScript thing, not really specific to Rails. Coincidentally, > I just made this sort of behavior in a Drupal site this morning. For this > form, there were fields that made sense for postal mail subscribers that > did not make sense for email subscribers. So I added a classname to each of > the field wrappers -- either ''postal'' or ''email'' and used that to make my > behavior work: > > http://jsfiddle.net/rk3vw/3/ > > This is using Prototype, I am sure you can use jQuery or "vanilla" > JavaScript if that''s your thing. > > Walter > > > > > -- > > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/8I3DBjMWlC0J. > > For more options, visit https://groups.google.com/groups/opt_out. > > > > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.