You could modify your view to show something like: "Customer.id :
Customer.first Costomer.last" in the ajax dropdown so when the
submitted data came through all you'd have to do is grab the first
string to the : sign for the id.
A cleaner approach I've used in the pass is a beforeSave() in the
model I'm working with.
For example:
Item belongsTo Company
In the Item add field I'll want to not only offer a drop down of
companies but offer a way to add a new company on the fly, so I'll
use an ajax autocomplete field and in the beforeSave() do something
like this:
[code]
function beforeSave(){
if(isset($this->data['Company']['name'])){
$this->Company->contain();
//Find the company, and set the id.
if($company = $this->Company->findByName($this->data['Company']
['name'])){
$this->data['Item']['company_id'] = $category['Company']
['id'];
}
//Or create it, and set the id.
else{
$company['Company']['name'] = $this->data['Company']['name'];
$this->Company->save($company);
$this->data['Item']['company_id'] = $this->Company->id;
}
}
return true;
}
[/code]
So when given a Company.name the model Item will either find the
already created Company.name and set its id, or create it first for
you, then set the id.
Hope that helps,
Nick
On Oct 20, 12:51 am, DAM <[email protected]> wrote:
> I'm developing on my university final year project.I implemented
> autocomplete input for customer name.It's working.Show customer first
> & last name but I want to pass customer_id for save.How can I
> implement this? pls help me!! thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---