I am getting the same problem as well.

I used formatResult to format the data being placed in my input but my
result callback is still getting the unformatted data as its 3rd
parameter.

Any ideas why?

Thanks,
Franz

On Aug 15, 2:32 am, Professor B <[EMAIL PROTECTED]> wrote:
> Thanks again, gentlemen.
>
> I am not complaining:  the thing is working for me now and I am
> grateful. But I still don't quite understand how the formatItem:
> callback option works with  result(handler) that fires when the user
> selects a value.
>
> My formatItem callback takes the data passed, does some processing to
> it and returns it. And the data thus processed turns up in the <li>
> elements that the user sees:  fine.
>
> However, theresult( handler ) takes 3 arguments, right?  "The first
> argument is a generic event object...The second argument refers to the
> selected data, which can be a plain string value or an array or
> object. The third argument is the formatted value that is inserted
> into the input field." Like so:
>
>           function(event, data, formatted) { /* ... */ }
>
> And that 'formatted' value comes from... where? I would think it was
> one of the values returned by the formatItem callback. Yet, in my
> example, although I return some formatted data from formatItem, the
> 'formatted' 3rd argument is identical to 'data.' Code example follows.
>
> Thanks again.
>
>         $("#deft_name").autocomplete('/defendants/autocompletedeftnames',
>         {
>                 max : 200,
>                 formatItem: function(row,position,total,searchTerm) {
>                         // server sends rows e.g., smith, joe#2874
>                         // so we pull out the alpha part for display
>                         return row.toString().split('#')[0];
>                 }
>          }
>         ).result(function(event, data, formatted) {
>                 event.target.value = '';
>                 var pieces = data.toString().split('#');
>                 if (pieces.length != 2) { return alert("Error: could not 
> parse "
> + data); }
>                 var name = pieces[0];
>                 var id = pieces[1];
>                 if ($('#deftDiv_' + id).length) {
>                         return alert("Defendant " + name+ " has already been 
> added");
>                 }
>                 // ugly part, don't look if  you have a weak stomach
>                 $('#defendants').append($('<div></div>').attr('id','deftDiv_' 
> +
> id)
>                         .append( $('<a></
> a>').attr('href','javascript:void(0)').text('[x]')
>                                 
> .click(function(e){$(this).parent().hide('slow',function(){
>                                      $('#'+this.id).remove();
>                                 });})
>                         )
>                         .append(" "+ name)
>                         .append($("<input type=\"hidden\">").attr( { 
> name:'deft_ids[]',
> value:  id }))
>                 )
>                 // alert("formatted is " + formatted + "\n data is " + data); 
> //
> and they are the same as one another
>         });

Reply via email to