# Observe\_form misbehaving - requests processed out of order?

**URL:** <https://www.ruby-forum.com/t/observe-form-misbehaving-requests-processed-out-of-order/124842>\
**Category:** Rails\
**Created:** [January 3, 2008, 12:24am UTC](https://www.ruby-forum.com/t/observe-form-misbehaving-requests-processed-out-of-order/124842 "2008-01-03T00:24:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [January 3, 2008, 12:24am UTC](https://www.ruby-forum.com/t/observe-form-misbehaving-requests-processed-out-of-order/124842/1 "2008-01-03T00:24:19Z")

</div>

scenario:  
I used the observe\_form to build a live search. It worked perfect until  
I loaded a large amount of data and tested it in a production  
environment.

symptoms:  
when I am searching for ‘john’ I type in ‘j’, ‘o’, ‘h’, and then finally  
‘n’. The observe field goes through and sends me the correct values but  
then searches for only ‘j’ at the end.

possible reason:  
I think it is because the ‘j’ request takes up more time then the full  
‘john’ and it still process that request, but it unfortunately processes  
them out of order.

possible solution:  
create a hidden field that increments the requests. If I get a request  
back that is less than the current one I know not to process it.

Any other ideas?

Any hints on how I would implement this? I’ve got my javascript  
increment function and check function, but I’m not quite sure how to  
work this out with the observe\_field. when would i fire these  
javascript functions off?

thanks

---

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [January 3, 2008, 12:35am UTC](https://www.ruby-forum.com/t/observe-form-misbehaving-requests-processed-out-of-order/124842/2 "2008-01-03T00:35:08Z")

</div>

Set a frequency of around 500 on the observe\_field. It’s calling the  
function on the letter j because that’s the first event that the field  
changes on.

---

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [January 3, 2008, 12:44am UTC](https://www.ruby-forum.com/t/observe-form-misbehaving-requests-processed-out-of-order/124842/3 "2008-01-03T00:44:47Z")

</div>

Ryan B. wrote:

> Set a frequency of around 500 on the observe\_field. It’s calling the  
> function on the letter j because that’s the first event that the field  
> changes on.

That would defeat the purpose of a live search. A live search responds  
to what is typed in the field. The observe field must be listening at a  
much smaller frequency than that. Example here:  
[http://www.recentrambles.com/pragmatic/view/59](http://www.recentrambles.com/pragmatic/view/59)

I should call the function with the letter j because, yes, it is the  
first event. the problem is that it takes longer and than the last  
request.

---

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [January 3, 2008, 4:28am UTC](https://www.ruby-forum.com/t/observe-form-misbehaving-requests-processed-out-of-order/124842/4 "2008-01-03T04:28:24Z")

</div>

On 1/2/08, Jimmy P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> but I’m not quite sure how to  
> work this out with the observe\_field. when would i fire these  
> javascript functions off?

Here’s the important bits from one I have setup:

Live Search: \<%= text\_field ‘search’, ‘term’, :size =\> 12 %\>

Wait!

\<%= observe\_field ‘search\_term’, :frequency =\> 1.0,  
:update =\> ‘target\_id’,  
:url =\> { :controller =\>  
‘search’,  
:action =\>  
‘search’ },  
:with =\> “‘search=’ +  
escape(value)”,  
:loading =\> “Element.show( ‘wait’  
);”,  
:complete =\> “Element.hide( ‘wait’  
);” %\>

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [January 7, 2008, 10:31pm UTC](https://www.ruby-forum.com/t/observe-form-misbehaving-requests-processed-out-of-order/124842/5 "2008-01-07T22:31:12Z")

</div>

Again, I’m not sure if we are understanding the problem. I believe I am  
using the observe field correctly, but it appears that the requests are  
getting out of order.

Has anyone seen this behavior?
