I have a form that tracks items allowed in certain places on campus. A radio button group controls whether the area in question is a physical room or a more genearl ‘project’. Either one has its value entered into the same field in the database.
Rooms and projects are stored in separate tables. I want to take advantage of jQuery UI’s auto-complete here. So far, the change event on the radio group switches the appropriate text for room and project, and toggles the class ‘roomAC’. The ‘roomAC’ class is the selector for the auto-complete.
I figured when I removed the class it would no longer let the auto-complete work, but it does. This is because the event is still bound to the DOM element. What I want to know is if there is a way to bind/unbind the auto-complete event? Or am I stuck re-creating the event-handler inside my if statement (the one the radio group)?
MY JS
//ROOM FIELD JQUERY-UI AUTO-COMPLETE
$(".roomAC").autocomplete({
source: "autocomplete.cfm",
minLength: 4
});
tl;dr
How do I bind and unbind the jQuery UI auto-complete event?
Regarding your question about unbinding autocomplete control, you could either disable it or change source with
.autocomplete( "option" , optionName , [value] )syntax.But if I understand your situation correctly, you actually want to send both the search term and source identifier. It could be achieved by using callback as source (in your autocomplete options). Documentation says:
This is function I have used with jQuery UI autocomplete:
This function also caches response. If you ignore that, the trick is within try/catch block.