I have some code that calls a partial to display one or more blocks
within a div tag. I want to have a close button (or cancel link) that
will fade that block but leave the others. Here is the code:
LINK:
<%= link_to_remote "Add Miscellaneous Link", :url => { :action
=>
:add_iyc_link } %>
add_iyc_link.rjs:
page.insert_html :bottom, ''links'', :partial =>
''add_iyc_link''
page.visual_effect :highlight, ''links''
_add_iyc_link.rhtml:
<p class="iyclink" id="iyclink">
<%= image_tag "cancel.png", :class =>
''close'', :onclick => "new
Effect.Fade(''iyclink'', {duration: 3})" %>
<label for="">Title</label><br/>
<%= text_field ''in_your_classroom_link'',
''title[]'', :size => ''30'',
:class => ''link'' %>
<br/>
<label for="">URL</label><br/>
<%= text_field ''in_your_classroom_link'',
''url[]'', :size => ''50'',
:class => ''link'' %>
<br/>
<label for="">Description</label> <span
class="markdown">[Markdown]</span><br/>
<%= text_area ''in_your_classroom_link'',
''bodytext[]'', :cols => ''70'',
:rows => ''5'' %>
</p>
Can this be done? The problem is when I have two or more blocks and
click the cancel button the first gets faded which is not the one I
want.
--
Posted via http://www.ruby-forum.com/.
The problem is that each of your <p> elements all have the same id. The
javascript works with the id of elements in the DOM to do it''s thing.
When
it tries to do it''s thing it finds the first element with the id
specified.
You need to specify each with a unique id.
One way would be to include a random string generation function in a
helper. eg
def random_id
chars = ("A".."Z") + ("a".."z") +
("0".."9")
(1..10).inject(String.new) { |str, i| str << chars[rand(chars.length)] }
end
then in your partial
<% rand_id = random_id %>
<p name="#{rand_id}" id="#{rand_id}">
other stuff in here
I think this should work unless you need the id to relate to the actual
record in the db
On 5/31/06, Seth Buntin <seth.buntin@coe.murraystate.edu>
wrote:>
> I have some code that calls a partial to display one or more blocks
> within a div tag. I want to have a close button (or cancel link) that
> will fade that block but leave the others. Here is the code:
>
> LINK:
> <%= link_to_remote "Add Miscellaneous Link", :url => {
:action =>
> :add_iyc_link } %>
>
> add_iyc_link.rjs:
> page.insert_html :bottom, ''links'', :partial =>
''add_iyc_link''
> page.visual_effect :highlight, ''links''
>
> _add_iyc_link.rhtml:
> <p class="iyclink" id="iyclink">
> <%= image_tag "cancel.png", :class =>
''close'', :onclick => "new
> Effect.Fade(''iyclink'', {duration: 3})" %>
> <label for="">Title</label><br/>
> <%= text_field ''in_your_classroom_link'',
''title[]'', :size => ''30'',
> :class => ''link'' %>
> <br/>
> <label for="">URL</label><br/>
> <%= text_field ''in_your_classroom_link'',
''url[]'', :size => ''50'',
> :class => ''link'' %>
> <br/>
> <label for="">Description</label> <span
> class="markdown">[Markdown]</span><br/>
> <%= text_area ''in_your_classroom_link'',
''bodytext[]'', :cols => ''70'',
> :rows => ''5'' %>
> </p>
>
> Can this be done? The problem is when I have two or more blocks and
> click the cancel button the first gets faded which is not the one I
> want.
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060531/4bf27324/attachment.html
The weird thing is when I put <% rand_id = random_id %> in my partial the rjs won''t display my partial. I can take it out and it works fine. Daniel ----- wrote:> The problem is that each of your <p> elements all have the same id. The > javascript works with the id of elements in the DOM to do it''s thing. > When > it tries to do it''s thing it finds the first element with the id > specified. > > You need to specify each with a unique id. > > One way would be to include a random string generation function in a > helper. eg > > def random_id > chars = ("A".."Z") + ("a".."z") + ("0".."9") > (1..10).inject(String.new) { |str, i| str << chars[rand(chars.length)] } > end > > > then in your partial > <% rand_id = random_id %> > <p name="#{rand_id}" id="#{rand_id}"> > other stuff in here > > I think this should work unless you need the id to relate to the actual > record in the db-- Posted via http://www.ruby-forum.com/.
Seth,
My bad.. the chars line should read
chars = ("A".."Z").to_a +
("a".."z").to_a + ("0".."9").to_a
or something similar
On 6/1/06, Seth Buntin <seth.buntin@coe.murraystate.edu>
wrote:>
> The weird thing is when I put <% rand_id = random_id %> in my partial
> the rjs won''t display my partial. I can take it out and it works
fine.
>
>
>
> Daniel ----- wrote:
> > The problem is that each of your <p> elements all have the same
id. The
> > javascript works with the id of elements in the DOM to do
it''s thing.
> > When
> > it tries to do it''s thing it finds the first element with the
id
> > specified.
> >
> > You need to specify each with a unique id.
> >
> > One way would be to include a random string generation function in a
> > helper. eg
> >
> > def random_id
> > chars = ("A".."Z") +
("a".."z") + ("0".."9")
> > (1..10).inject(String.new) { |str, i| str <<
chars[rand(chars.length)] }
> > end
> >
> >
> > then in your partial
> > <% rand_id = random_id %>
> > <p name="#{rand_id}" id="#{rand_id}">
> > other stuff in here
> >
> > I think this should work unless you need the id to relate to the
actual
> > record in the db
>
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060531/7d3c70e0/attachment.html
Thanks Daniel. That worked. Seth Daniel ----- wrote:> Seth, > > My bad.. the chars line should read > > chars = ("A".."Z").to_a + ("a".."z").to_a + ("0".."9").to_a > > or something similar-- Posted via http://www.ruby-forum.com/.