In the code below (Coffeescript), in the AJAX call for the jQuery autocomplete data source, On line 5 of the code, I am passing 2 params - term: and ll: For ll: I'm trying to get $(this) to be the DOM element that .autocomplete was applied to. In this case its $('[type="text"][name*="[location]"]') I need to reference that DOM element specifically with ($this) on line 5. However, I believe 'this' at that scope refers to something else that isn't a DOM element. Can someone please help explain what I need to do?
$('[type="text"][name*="[location]"]').autocomplete(
source: (request, response) ->
$.ajax
url: $('[type="text"][name*="[location]"]').data('autocomplete-source')
data: {term: request.term, ll: $(this).siblings('[name*="[geocode_location]"]')}
contentType: "application/json; charset=utf-8"
success: (data) ->
response $.map(data, (item) ->
value: item.value
label: item.label
address: item.address
)
focus: (event, ui) ->
event.preventDefault()
$(this).val ui.item.label
select: (event, ui) ->
event.preventDefault()
$(this).val ui.item.label
$(this).siblings('[name*="[foursquare_id]"]').val ui.item.value
).data("autocomplete")._renderItem = (ul, item) ->
$("<li>").data("item.autocomplete", item).append("<a>" + item.label + "<br>" + item.address + "</a>").appendTo ul