Make an input field autocomplete using jQuery

36 views
Skip to first unread message

Abhijeet

unread,
Jun 24, 2015, 8:13:44 PM6/24/15
to django-s...@googlegroups.com
I need to make an input field autocomplete using LookUp created in django. This field is not created using django form (bcoz of some requirements ) so i can not use 'AutoCompleteSelectField'.

What is the best way to make an input field autocomplete using jQuery/javascript ? 

I tries this 

function activateSelectableInput(lookup_url){
    var input_field = $("#MyInputField");
    input_field.addClass("autocompletewidget ui-autocomplete-input ui-widget ui-widget-content ui-corner-all ui-state-error");
    input_field.attr("data-selectable-url", lookup_url);
    input_field.attr("data-selectable-type","text");
    input_field.attr('data-selectable-allow-new','false');
    window.bindSelectables("body");
}


It lets me lookup and select value but does not raise any event

Mark Lavin

unread,
Jul 4, 2015, 6:25:24 AM7/4/15
to django-s...@googlegroups.com
Your method looks fine. Adding the classes is not needed because that will be done by jQuery UI/selectable on bind. You also don't need to call bindSelectable on the entire body. You can just call it on the new element.

What events are you listening for? I don't see any of that in this example.

--
You received this message because you are subscribed to the Google Groups "django-selectable" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-selecta...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages