2

I use jquery autocomplete.

And I want add to source URL attribute from this input. How?

This code don't work:

$('input.autocomplete').autocomplete({
    source: "/service/autocomplete/"+$(this).data('source'),
    minLength: 2,
    select: function( event, ui ) {
        console.log( ui.item );

}
2
  • by source url you mean this "/service/autocomplete/"+$(this).data('source')? Commented Aug 12, 2013 at 15:08
  • Your going to have to be a bit more descriptive than that. And I want add to source URL attribute from this input. How? really isn't giving us much to go on. What do you mean you want to add to it? do you mean you want to dynamically change it on a per need basis? what exactly outside of the autocomplete stock functions are you attempting to do? Commented Aug 12, 2013 at 15:10

1 Answer 1

4

Where you have it placed this will not mean the element the plugin is being instantiated on. If you need this behaviour you need to create each instance in a loop so that you can get access to the attributes on each specific matched element:

$('input.autocomplete').each(function() {
    var $el = $(this);
    var source = "/service/autocomplete/" + $el.data('source');

    $el.autocomplete({
        source: source,
        minLength: 2,
        select: function( event, ui ) {
            console.log( ui.item );    
        }
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

Yes,, i love this! :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.