Looks promising, will give it a try. Thanks for the response.
On 18 Apr, 16:28, chowsapal <[EMAIL PROTECTED]> wrote:
> The regular $ajax->autocomplete isn't a select box, but it functions
> much like one if the CSS is set right for your ul. Are you trying to
> use it in conjunction with a select box? One thing you could do is
> run it something like this:
>
> (in autocomplete.ctp:)
> <ul class="autocompleteDropdown">
> <?php if (!empty($posts)) foreach($posts as $entry): ?>
> <li class="autocompleteEntry"><?php echo preg_replace('/^\[([0-9]+)
> \]: /', '<span style="display:none">$1</span>', $entry); ?></li>
> <?php endforeach; ?>
> </ul>
>
> (in your view:)
> <?php echo $ajax->autocomplete('Model.field', '/controller/
> autocomplete', array('size' => '36', 'indicator' => 'field_ind',
> 'updateElement' => 'updateField')); ?><img src="/img/waiting.gif"
> id="field_ind" style="display: none; width:30px" />
>
> (javascript in your view:)
> function updateField(item) {
> itemText = item.innerHTML;
> $('FieldId').value = itemText.replace(/^<span style="display:
> none;">(\d+)<\/span>(.*)$/, "$1");
> $('AutocompleteFieldName').value = itemText.replace(/^<span
> style="display: none;">(\d+)<\/span>(.*)$/, "$2");
>
> }
>
> The above code works for a hidden field called Field.id -- I can't
> remember if you set the value for a select box exactly like that, but
> I think you get the idea. Basically, you put the ID for your field in
> a hidden span inside your list, then hijack the updateElement function
> of the autocomplete box to fill in the ID of your selected item, as
> well as the text of the autocomplete field itself.
>
> HTH
> -chowsapal
>
> On Apr 18, 9:34 am, evenshadowshaveshadows
>
> <[EMAIL PROTECTED]> wrote:
> > Hello! I'm sort of new to the wonderful world of CakePHP and AJAX.
> > Anyhow I have now come to a point where I'm kind of stuck and in need
> > of some tips from more experienced users.
>
> > In my view /invoices/create I have a form containing:
> > * A select box containting company names and one special option "New
> > company"
> > * A couple of input fields with company information.
>
> > When an existing company is selected I want to be able to do this:
> > * Retrieve the company information form my database and fill in the
> > fields.
> > * Disable the input fields so that no new data can be inserted.
>
> > When "New company" option is selected (it is selected by default) I
> > want to be able to do this:
> > * Clear the input fields.
> > * Enable the input fields (if disabled).
>
> > I've been trying different solutions using AJAX and the onchange event
> > but I haven't been able to come up with a solution that was good
> > enough to actually use. I've also been browsing different forums
> > looking for a really simple example of good auto completion using AJAX
> > without any real success. What I want is a really really simple
> > example of how to achieve the above or something similar. I will be
> > very grateful for any help or tips.
>
> > Thanks in advance.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---