The Cool Web Guy
2008-Mar-17 04:37 UTC
Setting the Element ID of inserted partials with javascript
Hi, Lets say I have a form with multiple task elements, for adding tasks to a project, and a link_to_function which inserts a new task using page.insert_html :partial eg: <div id="tasks">tasks holder</div> <%= link_to_function "Add Task" do |page| page.insert_html :bottom, :tasks, :partial => ''task'', :object => @task.new end %> I know when I do a render collection that each partial has a partial_name_counter variable eg: task_counter, but when I create a task using the javascript helper this variable no longer works because it defaults to 1 (as it was when the partial was rendered into the javascript query), is there anyway to get the same attribute using javascript?, or at least set a unique id to each task which is created using the javascript helper? Thanks in advance. -Ivan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Subbu
2008-Mar-17 06:20 UTC
Re: Setting the Element ID of inserted partials with javascript
If you want that ID in order to remove the newly added task, you can use Prototype''s up function. Please take a look at http://railscasts.com/episodes/74. Not sure if this is what you are trying to do. On Mar 16, 9:37 pm, The Cool Web Guy <ivanvander...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > Lets say I have a form with multiple task elements, for adding tasks > to a project, and a link_to_function which inserts a new task using > page.insert_html :partial > eg: > <div id="tasks">tasks holder</div> > <%= link_to_function "Add Task" do |page| > page.insert_html :bottom, :tasks, :partial => ''task'', :object => > @task.new > end %> > > I know when I do a render collection that each partial has a > partial_name_counter variable eg: task_counter, but when I create a > task using the javascript helper this variable no longer works because > it defaults to 1 (as it was when the partial was rendered into the > javascript query), is there anyway to get the same attribute using > javascript?, or at least set a unique id to each task which is created > using the javascript helper? > > Thanks in advance. > -Ivan--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The Cool Web Guy
2008-Mar-17 10:36 UTC
Re: Setting the Element ID of inserted partials with javascript
Thats a good idea I''ll check it out, What i am actually doing is using the spry framework to provide validation on the textfield and unfortunately it has to be applied on a per id basis, not on all elements of a certain class, so therefor i need to be able to set a unique id to each task input field or containing div (as spry can be applied to a div then auto assign to first input) On Mar 17, 5:20 pm, Subbu <subramani.athiku...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> If you want that ID in order to remove the newly added task, you can > use Prototype''s up function. Please take a look athttp://railscasts.com/episodes/74. > Not sure if this is what you are trying to do. > > On Mar 16, 9:37 pm, The Cool Web Guy <ivanvander...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > Lets say I have a form with multiple task elements, for adding tasks > > to a project, and a link_to_function which inserts a new task using > > page.insert_html :partial > > eg: > > <div id="tasks">tasks holder</div> > > <%= link_to_function "Add Task" do |page| > > page.insert_html :bottom, :tasks, :partial => ''task'', :object => > > @task.new > > end %> > > > I know when I do a render collection that each partial has a > > partial_name_counter variable eg: task_counter, but when I create a > > task using the javascript helper this variable no longer works because > > it defaults to 1 (as it was when the partial was rendered into the > > javascript query), is there anyway to get the same attribute using > > javascript?, or at least set a unique id to each task which is created > > using the javascript helper? > > > Thanks in advance. > > -Ivan--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---