Re: Autocomplete on 1.1.13
I ended up using a regex to get the username and then queried the database for the username in the controller. From this I got the id. Probably not the best way, but it seemed like the easiest and the one that would work on the widest range of platforms. Mike. On 3/17/07, Jeremy Pointer <[EMAIL PROTECTED]> wrote: > Isn't it a small world > > This is from something I did, No change in the controller but I've > modified the below views, the key is to set the user id as the id of the > tag in autocomplet, and then have > a 'user_id' input and a touch of javascritpt in the send view to update > the id field, then set the 'afterUpdateElement' option in > $ajax->autocomplete() > > autocomplete.thtml: > > > > $user['User']['username'].' ('.$user['User']['fname'].' > '.$user['User']['lname'].')'; ?> > > > > > send.thtml: > > > > > input('Message/user_id'); ?> > > function getSelectionId(text, li) { > alert(li.id); > document.getElementById('MessageUserId').value=li.id; > } > > autocomplete('Message/user','/contacts/autocomplete', > array('size' => 40, > 'afterUpdateElement'=>'getSelectionId' > ) > ); > ?> > > textarea('Message/message', array('cols' => '60', > 'rows' => '10')); ?> > > submit('Send');?> > > > > HTH > JermWorm > > Mike Griffin wrote: > > On 3/16/07, fredBH <[EMAIL PROTECTED]> wrote: > > > >> can you post the code ? > >> > > > > Sure, here is the sutocomplete.thtml file. It returns the username > > and then the full name in brackets > > > > > > > '.$user['User']['lname'].')'; ?> > > > > > > > > The form is in send.thtml > > > > > > autocomplete('Message/user', > > '/Messages/autocomplete', array('size' => 40)); ?> > > > > textarea('Message/message', array('cols' => '60', > > 'rows' => '10')); ?> > > > > submit('Send');?> > > > > > > > > And the autocomplete function from the messages controller: > > function autocomplete() { > > $this->set('users', $this->User->findAll(array('User.username' => > > 'LIKE '.$this->data['Message']['user'].'%'), array('User.username', > > 'User.fname', 'User.lname', 'User.id'), 'username DESC',null, null, > > 0)); > > $this->layout = "ajax"; > > } > > > > So the function returns the User.id but I cant see how to pass that to > > the view and back again. > > > > Mike. > > > > > > > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Autocomplete on 1.1.13
Isn't it a small world This is from something I did, No change in the controller but I've modified the below views, the key is to set the user id as the id of the tag in autocomplet, and then have a 'user_id' input and a touch of javascritpt in the send view to update the id field, then set the 'afterUpdateElement' option in $ajax->autocomplete() autocomplete.thtml: send.thtml: input('Message/user_id'); ?> function getSelectionId(text, li) { alert(li.id); document.getElementById('MessageUserId').value=li.id; } autocomplete('Message/user','/contacts/autocomplete', array('size' => 40, 'afterUpdateElement'=>'getSelectionId' ) ); ?> textarea('Message/message', array('cols' => '60', 'rows' => '10')); ?> submit('Send');?> HTH JermWorm Mike Griffin wrote: > On 3/16/07, fredBH <[EMAIL PROTECTED]> wrote: > >> can you post the code ? >> > > Sure, here is the sutocomplete.thtml file. It returns the username > and then the full name in brackets > > > '.$user['User']['lname'].')'; ?> > > > > The form is in send.thtml > > > autocomplete('Message/user', > '/Messages/autocomplete', array('size' => 40)); ?> > > textarea('Message/message', array('cols' => '60', > 'rows' => '10')); ?> > > submit('Send');?> > > > > And the autocomplete function from the messages controller: > function autocomplete() { > $this->set('users', $this->User->findAll(array('User.username' => > 'LIKE '.$this->data['Message']['user'].'%'), array('User.username', > 'User.fname', 'User.lname', 'User.id'), 'username DESC',null, null, > 0)); > $this->layout = "ajax"; > } > > So the function returns the User.id but I cant see how to pass that to > the view and back again. > > Mike. > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~--- begin:vcard fn:Jeremy Pointer n:Pointer;Jeremy adr:;;Box 499;Krugersdorp;Gauteng;1740;South Africa email;internet:[EMAIL PROTECTED] tel;work:+27 11 665-2445 tel;fax:+27 86 5013109 tel;cell:+27 82 3724769 x-mozilla-html:TRUE version:2.1 end:vcard
Re: Autocomplete on 1.1.13
On 3/16/07, fredBH <[EMAIL PROTECTED]> wrote: > > can you post the code ? Sure, here is the sutocomplete.thtml file. It returns the username and then the full name in brackets The form is in send.thtml autocomplete('Message/user', '/Messages/autocomplete', array('size' => 40)); ?> textarea('Message/message', array('cols' => '60', 'rows' => '10')); ?> submit('Send');?> And the autocomplete function from the messages controller: function autocomplete() { $this->set('users', $this->User->findAll(array('User.username' => 'LIKE '.$this->data['Message']['user'].'%'), array('User.username', 'User.fname', 'User.lname', 'User.id'), 'username DESC',null, null, 0)); $this->layout = "ajax"; } So the function returns the User.id but I cant see how to pass that to the view and back again. Mike. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Autocomplete on 1.1.13
can you post the code ? On 16 mar, 08:10, "Mike Griffin" <[EMAIL PROTECTED]> wrote: > Hi. > > I have the autocomplete function working properly and returning > results. I want it to show the username of a user but to return the > id of that user. > > Is there any way to do this? > I have tried using the "with" option, but that didnt seem to do anything at > all. > > Thanks, > Mike. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---