AJAX - weird display

Hi,

I have a tabular (it’s a form actually) with text_fields and buttons.
I wanted to diplay a particular row when a button is set to ‘yes’.
Everything’s working fine except, that my new row is diplayed at the top
of the array and not where I want. I can do page.add_html/delete and
specify bottom, but I don’t understand why my snippet doesn’t work.

Any idea?

Used to programming in Ruby? <%= radio_button :form,:ruby,:yes, :onclick => remote_function(:url => {:controller => '/my_controler', :action =>'my_action', :ruby => 'yes'}, :method => :post)%> <%= radio_button :form,:ruby,:yes, :onclick => remote_function(:url => {:controller => '/my_controler', :action =>'my_action', :ruby => 'no'}, :method => :post)%>
<%= render :partial => 'yes' %>

And the partial yes:
<% if @ruby -%>

bla bla bla ../.. <% end -%>

With the rjs
page.replace_html ‘my_id’, :partial => ‘yes’

Thanks!


,========================.
| Pierre-Alexandre M. |
| email : [email protected] |
`========================’

Pierre-Alexandre M. wrote:

Hi,

I have a tabular (it’s a form actually) with text_fields and buttons.
I wanted to diplay a particular row when a button is set to ‘yes’.
Everything’s working fine except, that my new row is diplayed at the top
of the array and not where I want. I can do page.add_html/delete and
specify bottom, but I don’t understand why my snippet doesn’t work.

Hi Pierre,
This looks perfectly correct to me. I do something similar but with an
unordered list, and div’s around each of the

  • lines. replace_html
    cleanly replaces just the line I want to change. I wonder if it is just
    a bug related to tables. I almost never use a table anymore now that
    I’ve learned css.

    best of luck,
    jp

  • Thanks for your reply.

    On Wed, Feb 28, 2007 at 05:07:46PM +0100, Jeff P. wrote :

    This looks perfectly correct to me. I do something similar but with an
    unordered list, and div’s around each of the

  • lines. replace_html
    cleanly replaces just the line I want to change.
  • I have the same snippet for lists too and it works actually.

    I wonder if it is just a bug related to tables.

    Maybe. I’m waiting for other replies before going deeper in this problem
    to see where’s the bug. I’m wondering if it is due to the ‘form’ fields.

    I almost never use a table anymore now that I’ve learned css.

    Actually, I have an application displaying a whole bunch of data (think
    of
    thousands rows/columns of structured data). So tabulars are perfect for
    me :slight_smile:

    Have fun,


    pam

    <%= render :partial => 'yes' %>

    the above is not valid html. applying your partial, it’s even more
    invalid.

    ...

    that’s not going to work and your browser will screw up the rendering,
    but you already know that.

    try:

    <%= render :partial => 'yes' -%>

    And the partial yes:
    <% if @ruby -%>

    bla bla bla ../.. <% end -%>

    rjs stays the same

    keep in mind the # of td’s in your partial should be the same as the
    rest of the table, or have a colspan attribute.

    Hi Pierre,

    Pierre-Alexandre M. wrote:

    I wonder if it is just a bug related to tables.

    Maybe. I’m waiting for other replies before going deeper in this problem
    to see where’s the bug. I’m wondering if it is due to the ‘form’ fields.

    It’s not a bug with tables. Ajax works on XHTML DOM elements. Tables
    use a
    different DOM. The explanation of the situation is on MSDN. If you’re
    going to use Ajax, you’re either going to use CSS, or you’re going to
    end up
    with some very ugly code because

    's can’t be updated / replaced. If
    you
    really need to use tables, the best way I’ve heard of is to replace your

    structure with

    It seems you can do a page.replace on a

    . I haven’t tried it.
    My
    recommendation is to bite the bullet and learn a little CSS. You can
    use
    absolute positioning on an
  • to get the table effect very easily,
    your
    code will be lots cleaner, and you can style the result in ways you’ll
    never
    be able to with a table. OTOH, I hear the XHTML DOM is going to be
    extended
    and CSS3.x is going to include tables. If you can wait :wink:

    Best regards,
    Bill

  • On Wed, Feb 28, 2007 at 08:34:31AM -0500, Chris H. wrote :

    try:

    <%= render :partial => 'yes' -%>

    It works! Thanks a lot!

    keep in mind the # of td’s in your partial should be the same as the
    rest of the table, or have a colspan attribute.

    Actually the colspan was already there :wink:

    Have fun,


    ,========================.
    | Pierre-Alexandre M. |
    | email : [email protected] |
    `========================’

    On Wed, Feb 28, 2007 at 07:12:45PM -0600, Bill W. wrote :

    Hi Pierre,

    Hi!

    It seems you can do a page.replace on a

    . I haven’t tried it.

    Unfortunately, it doesn’t work either :’( I will forget about this AJAX
    trick.

    My recommendation is to bite the bullet and learn a little CSS. You can use
    absolute positioning on an

  • to get the table effect very easily, your
    code will be lots cleaner, and you can style the result in ways you’ll never
    be able to with a table.
  • You’re probably right, but at this point on I don’t have the time to
    learn
    CSS and replace the 200 tables of my application :wink: Maybe in the RC2…

    OTOH, I hear the XHTML DOM is going to be extended
    and CSS3.x is going to include tables. If you can wait :wink:

    I’m pretty sure my customers can’t wait!

    Thanks for your explanation,

    ++


    ,========================.
    | Pierre-Alexandre M. |
    | email : [email protected] |
    `========================’