Hello, Wondering if some Ajax/prototype/scriptaculous practicioners can give me some hints on how to do this. Let''s say I have a todo list and want to add a new item. Easy enough. I can have a hidden div containing my new item form and show it by clicking on a "add new item" that contains a Element.show (''my_new_item_form''). But let''s say I don''t want to immediatly write that new item to my db. I want to enter several new items and then write all elements to the db after hitting submit all. Element.show only shows already created divs. So how do a create a new div? In other words, how can I have a "add new item" link that can be clicked over and over to create a new input element each time? All would be validated and written to the db after hitting a "submit changes" link? Thanks very much, Steve _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi, Steve, I can''t say what would be best rails-practice, but here is what I would do: 1. I would initially create a <div id="new_elements_container"> 2. I would then add a <div id="new_element_form"> into that div and toggle its appearance with the css-display flag (see new Effect.Fade and new Effect.Appear at script.aculo.us) 3. I would insert new Elements that get created by the form without server interaction with new Insertion.Bottom(''new elements_container'') - see script.aculo.us. The new elements would then populate the ''new_elements_container'' 4. Finally I would write some clientside javascript that extracts all elements out of the ''new_elements_container'', sends them to the serverside, where the get further extracted, validated and written to the persistence layer (that would happen onclick of ''submit all-button'') regards Jan Prill Steve Odom wrote:> Hello, > > Wondering if some Ajax/prototype/scriptaculous practicioners can give > me some hints on how to do this. Let''s say I have a todo list and want > to add a new item. Easy enough. I can have a hidden div containing my > new item form and show it by clicking on a "add new item" that > contains a Element.show(''my_new_item_form''). > > But let''s say I don''t want to immediatly write that new item to my db. > I want to enter several new items and then write all elements to the > db after hitting submit all. Element.show only shows already created divs. > > So how do a create a new div? In other words, how can I have a "add > new item" link that can be clicked over and over to create a new input > element each time? All would be validated and written to the db after > hitting a "submit changes" link? > > Thanks very much, > > Steve > >------------------------------------------------------------------------ > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >
Hey Steve, I recently did something like this with a CMS I''m working on. I think what you''re looking for is `Insertion.Bottom` from the prototype library. I haven''t looked around to see if Rails supports this, but it''s in the Prototype library anyway so use away. link_to_function ''Add New Item'', ''new Insertion.Bottom([list_id], $ ([new_item_div_id])'' If you use a submit button to just submit the form or use the Prototype library to Serialize the Form and send it on with AJAX. If you want some more depth into the prototype library this page is great: http://www.sergiopereira.com/articles/prototype.js.html#Reference Hope that helps, --Jeff On Nov 6, 2005, at 4:19 PM, Steve Odom wrote:> Hello, > > Wondering if some Ajax/prototype/scriptaculous practicioners can > give me some hints on how to do this. Let''s say I have a todo list > and want to add a new item. Easy enough. I can have a hidden div > containing my new item form and show it by clicking on a "add new > item" that contains a Element.show(''my_new_item_form''). > > But let''s say I don''t want to immediatly write that new item to my > db. I want to enter several new items and then write all elements > to the db after hitting submit all. Element.show only shows already > created divs. > > So how do a create a new div? In other words, how can I have a "add > new item" link that can be clicked over and over to create a new > input element each time? All would be validated and written to the > db after hitting a "submit changes" link? > > Thanks very much, > > Steve > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Thanks Jeff and Jan. The Insertion.Bottom was exactly what I was looking for. Steve On 11/7/05, Smick Jeff <rails_lists-m0qWdWgHGwnKl/7hFL4KYti2O/JbrIOy@public.gmane.org> wrote:> > Hey Steve, > > I recently did something like this with a CMS I''m working on. > I think what you''re looking for is `Insertion.Bottom` from the > prototype library. I haven''t looked around to see if Rails supports > this, but it''s in the Prototype library anyway so use away. > > link_to_function ''Add New Item'', ''new Insertion.Bottom([list_id], $ > ([new_item_div_id])'' > > If you use a submit button to just submit the form or use the > Prototype library to Serialize the Form and send it on with AJAX. > > If you want some more depth into the prototype library this page is > great: http://www.sergiopereira.com/articles/prototype.js.html#Reference > > Hope that helps, > --Jeff > > On Nov 6, 2005, at 4:19 PM, Steve Odom wrote: > > > > > Hello, > > > > Wondering if some Ajax/prototype/scriptaculous practicioners can > > give me some hints on how to do this. Let''s say I have a todo list > > and want to add a new item. Easy enough. I can have a hidden div > > containing my new item form and show it by clicking on a "add new > > item" that contains a Element.show(''my_new_item_form''). > > > > But let''s say I don''t want to immediatly write that new item to my > > db. I want to enter several new items and then write all elements > > to the db after hitting submit all. Element.show only shows already > > created divs. > > > > So how do a create a new div? In other words, how can I have a "add > > new item" link that can be clicked over and over to create a new > > input element each time? All would be validated and written to the > > db after hitting a "submit changes" link? > > > > Thanks very much, > > > > Steve > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails