I have the following layout: (the reason I'm putting the search form into its on block is so that the form isn't reloaded when #content is updated causing loss of focus and other issues when entering data into the field)
<div class="row-fluid">
<?php echo $this->Session->flash(); ?>
<div class="offset10 span2">
<?php echo $this->fetch('search'); ?>
</div>
<div class="row-fluid">
<div class="span3">
<?php echo $this->fetch('sidebar'); ?>
</div>
<div id="content" class="span9">
<?php echo $this->fetch('content'); ?>
</div>
</div>
</div>
and the following in my index views:
<?php $this->start('search'); ?>
<?php
$data = $this->Js->get('#ItemIndexForm')->serializeForm(array('isForm' => true, 'inline' => true));
$this->Js->get('#ItemIndexForm #ItemName')->event('keyup',$this->Js->request(array('action' => 'index'), array('update' => '#content', 'data' => $data, 'async' => true, 'method' => 'POST')));
$this->Js->get('#ItemIndexForm')->event('submit', $this->Js->request(array('action' => 'index'), array('update' => '#content','data' => $data,'async' => true, 'method' => 'POST')));
?>
<?php echo $this->Form->create('Item'); ?>
<?php echo $this->Form->input('Item.name'); ?>
<?php echo $this->Form->submit(); ?>
<?php echo $this->Form->end(); ?>
<?php $this->end(); ?>
When I submit the form or press a key everything works as expected a request is fired off and #content is updated.
However, each request results in an exponential number of requests, based on what I know about jquery the problem is that its rebinding the keyup and submit bindings when its receiving the new data. I'm guessing that having the search form fetched from its own content block is whats causing this behavior. Is there a better way to go about this? How can I fix it?
-- Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment