Monday, January 30, 2012

multiple depending selectfields with ajax?

using cakephp 1.3
jquery 1.7.1

i tried to get the following thing working

i have three tables
jobs
customers
customer_contacts

now, when i add a new job the user should be able to select the customer and after that only one of the contacts of this customer. I have done the following:

customer_contacts_controller
CODE
public $helpers = array('Js' => array('Jquery'));
public $components = array('RequestHandler');
function get(){
       $customerContacts = $this->CustomerContact->find('all', array('conditions' => 'Customer.Id = 2'));
       $this->set('customerContacts', $customerContacts);
   }

Here i get only the contact with the customer_id 2 for testing. With pr() i get the right result here. So i am right at this point.

View Jobs
CODE
echo $this->Form->input('customer_id', array('id' => 'customer'));
echo $this->Form->input('customer_contact_id', array('id' => 'customercontact'));
$this->Js->get("#customer")->event('change','$("#customercontact").load("customerContacts/get")');
echo $this->Js->writeBuffer();


Ok, and this isnt working. If i select a customer the customer contact selectfield will be cleared but nothing further happend. I know the load() is for html injection but i have no idea how to get the output from the controller method get() into my selectfield.

Greets Dennis
--  Dennis Reinert-Frerich  

No comments: