# Ajax: Multiple Element Update

**URL:** <https://www.ruby-forum.com/t/ajax-multiple-element-update/52315>\
**Category:** Rails\
**Created:** [January 12, 2006, 7:56pm UTC](https://www.ruby-forum.com/t/ajax-multiple-element-update/52315 "2006-01-12T19:56:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dylan\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@Dylan\_S](https://www.ruby-forum.com/u/Dylan_S)\
**Post date:** [January 12, 2006, 7:56pm UTC](https://www.ruby-forum.com/t/ajax-multiple-element-update/52315/1 "2006-01-12T19:56:35Z")

</div>

I’m trying to apply an Effect.Highlight only to elements of a Form that  
was  
submitted.  
So if a user updated 2 fields of a 10 field form, the Effect.Highlight  
would  
be applied to the 2 fields… showing the user what was updated.

My first attempt was to use the :complete=\>“eval(request.responseText)”  
…  
however, the template that get’s rendered won’t know what elements to  
apply  
the Effect too.  
My second attempt was to use a Javascript call, like the following…  
but  
don’t know the correct syntax to use to pull the elements modified from  
the  
Form:

\<% content\_for(“page\_scripts”) do -%\>  
function field\_edited() {  
var field = $(‘field’); // how do i figure out what was  
edited from the Form params ?  
new Effect.Highlight(field);  
}

# Any insight into this would be great, as I’ve been stumbling over this for quite some time now. Thanks !

Dylan

---

<div class="post-metadata">

**Author:** ![Dylan\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@Dylan\_S](https://www.ruby-forum.com/u/Dylan_S)\
**Post date:** [January 12, 2006, 8:04pm UTC](https://www.ruby-forum.com/t/ajax-multiple-element-update/52315/2 "2006-01-12T20:04:30Z")

</div>

I think this is a doubly loaded question. Not clear how/when you’ll show  
the highlighted elements. But here is my take on it.

1. Try to deal with the form diff in the ajax call. You know what the  
form was and now what the form is. So you can diff out the user changes  
and return the form attributes that have changed.

2. Use an rjs template on the way back and highlight the updated fields  
based on you diff.

Hope this helps…

---

<div class="post-metadata">

**Author:** ![Dylan\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@Dylan\_S](https://www.ruby-forum.com/u/Dylan_S)\
**Post date:** [January 12, 2006, 9:12pm UTC](https://www.ruby-forum.com/t/ajax-multiple-element-update/52315/3 "2006-01-12T21:12:19Z")

</div>

Thanks derailed…

1. You mean within the action called by Ajax (ie: a form\_remote\_tag) ?  
On updates for example, I’m just doing an “update\_attributes” on the  
model… but I could diff out what has changed and what hasn’t… then  
pass  
that hash back to the view. At this point however, I’m not too sure how  
to  
tie in the JS… and, in the whole scheme of things, effect the exact  
elements that relate to these form fields (ie: div’s surrounding each  
form  
field ).

2. This requires edge, or a plugin, correct ?

# Thanks !

Dylan

---

<div class="post-metadata">

**Author:** ![Dylan\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@Dylan\_S](https://www.ruby-forum.com/u/Dylan_S)\
**Post date:** [January 16, 2006, 6:10am UTC](https://www.ruby-forum.com/t/ajax-multiple-element-update/52315/4 "2006-01-16T06:10:15Z")

</div>

> From a controller action, after a form submit, is there a way to pass some  
> data to the template (or RJS template if you’re using them) that is  
> going to  
> be rendered ?

For example, passing the template some information as to what elements  
to  
effect.

---

<div class="post-metadata">

**Author:** ![Dylan\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@Dylan\_S](https://www.ruby-forum.com/u/Dylan_S)\
**Post date:** [January 13, 2006, 3:57am UTC](https://www.ruby-forum.com/t/ajax-multiple-element-update/52315/5 "2006-01-13T03:57:45Z")

</div>

Dylan,

```
Take a look at the rjs plugin. You don't need to run to the edge...
You can find all the info you need here:

http://www.codyfauser.com/articles/2005/12/02/rails-rjs-templates-plugin

```

Good luck !!

---

<div class="post-metadata">

**Author:** ![Dylan\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@Dylan\_S](https://www.ruby-forum.com/u/Dylan_S)\
**Post date:** [January 16, 2006, 7:26pm UTC](https://www.ruby-forum.com/t/ajax-multiple-element-update/52315/6 "2006-01-16T19:26:07Z")

</div>

If anybody was interested, I found this post which pretty much solves my  
problem. Not sure if this is the best approach… but it works !  
[http://www.cube6media.com/weblog/entry/2005/11/24/rails-ajax-form-error-handling](http://www.cube6media.com/weblog/entry/2005/11/24/rails-ajax-form-error-handling)
