How do I create a form that allows users to add additional instances of the same field if needed

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I create a form that allows users to add additional instances of the same field if needed

fugee ohu
Let's say I wanna let users add all their pet's on the same form but I don't know how many pets they have I need to let the user provide values for multiple attributes for each pet but won't be creating a pet's table Rather, on completion going to create a text list of the users pets How would I do 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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ac4b98c8-12ee-4ba9-b643-cd759d8c40b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How do I create a form that allows users to add additional instances of the same field if needed

Walter Lee Davis
You _could_ do this, but it's going to be a lot of trouble. Is there a reason why you don't want to add a pets table (and Pet model)? Then it would simply be a matter of adding a couple lines to your User model, and changing the users/_form partial to be a nested form.

class User < ApplicationModel
  has_many :pets
  accepts_nested_attributes_for :pets
  ...

class Pet < ApplicationModel
  belongs_to :user
  ...

Walter

> On Apr 13, 2017, at 4:41 AM, fugee ohu <[hidden email]> wrote:
>
> Let's say I wanna let users add all their pet's on the same form but I don't know how many pets they have I need to let the user provide values for multiple attributes for each pet but won't be creating a pet's table Rather, on completion going to create a text list of the users pets How would I do 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 [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ac4b98c8-12ee-4ba9-b643-cd759d8c40b8%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4869DA79-07AB-4224-AEB1-27841C67C77B%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How do I create a form that allows users to add additional instances of the same field if needed

André Orvalho
 You could also use https://harvesthq.github.io/chosen/ 

or

this http://stackoverflow.com/questions/39921381/adding-a-tag-if-it-doesnt-exist-in-rails-chosen-rails

google a little around I know I have done this a long time ago and it wasn't that hard.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/528da008-436a-4374-a509-dd8a7b742423%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How do I create a form that allows users to add additional instances of the same field if needed

fugee ohu
In reply to this post by Walter Lee Davis


On Thursday, April 13, 2017 at 8:22:59 AM UTC-4, Walter Lee Davis wrote:
You _could_ do this, but it's going to be a lot of trouble. Is there a reason why you don't want to add a pets table (and Pet model)? Then it would simply be a matter of adding a couple lines to your User model, and changing the users/_form partial to be a nested form.

class User < ApplicationModel
  has_many :pets
  accepts_nested_attributes_for :pets
  ...

class Pet < ApplicationModel
  belongs_to :user
  ...

Walter

> On Apr 13, 2017, at 4:41 AM, fugee ohu <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="fodfDiWCAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">fuge...@...> wrote:
>
> Let's say I wanna let users add all their pet's on the same form but I don't know how many pets they have I need to let the user provide values for multiple attributes for each pet but won't be creating a pet's table Rather, on completion going to create a text list of the users pets How would I do 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="fodfDiWCAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="fodfDiWCAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
> To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/ac4b98c8-12ee-4ba9-b643-cd759d8c40b8%40googlegroups.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/ac4b98c8-12ee-4ba9-b643-cd759d8c40b8%40googlegroups.com&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/ac4b98c8-12ee-4ba9-b643-cd759d8c40b8%40googlegroups.com&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/ac4b98c8-12ee-4ba9-b643-cd759d8c40b8%40googlegroups.com.
> For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.


Thanks Colin, that's what I did for now I've seen this in android adding contact's  phone numbers, you can keep pressing the new button and it adds a field set for you to put the number and type (home,work,mobile...)

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8ba03d40-f87a-43eb-9854-08d32e29255d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How do I create a form that allows users to add additional instances of the same field if needed

fugee ohu
In reply to this post by Walter Lee Davis


On Thursday, April 13, 2017 at 8:22:59 AM UTC-4, Walter Lee Davis wrote:
You _could_ do this, but it's going to be a lot of trouble. Is there a reason why you don't want to add a pets table (and Pet model)? Then it would simply be a matter of adding a couple lines to your User model, and changing the users/_form partial to be a nested form.

class User < ApplicationModel
  has_many :pets
  accepts_nested_attributes_for :pets
  ...

class Pet < ApplicationModel
  belongs_to :user
  ...

Walter

> On Apr 13, 2017, at 4:41 AM, fugee ohu <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="fodfDiWCAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">fuge...@...> wrote:
>
> Let's say I wanna let users add all their pet's on the same form but I don't know how many pets they have I need to let the user provide values for multiple attributes for each pet but won't be creating a pet's table Rather, on completion going to create a text list of the users pets How would I do 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="fodfDiWCAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="fodfDiWCAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
> To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/ac4b98c8-12ee-4ba9-b643-cd759d8c40b8%40googlegroups.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/ac4b98c8-12ee-4ba9-b643-cd759d8c40b8%40googlegroups.com&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/ac4b98c8-12ee-4ba9-b643-cd759d8c40b8%40googlegroups.com&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/ac4b98c8-12ee-4ba9-b643-cd759d8c40b8%40googlegroups.com.
> For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.


Thanks Walter, that's what I did for now I've seen this in android adding contact's  phone numbers, you can keep pressing the new button and it adds a field set for you to put the number and type (home,work,mobile...)
 

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3721b849-2758-4377-bc24-e9470f03c7a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.