help with autocomplete text input |
hello, please help with autocomplete input text with reference to a database
It's pretty easy.
There's an ajax request that gets fired when someone is typing in an input box. The ajax request sends the content of the input box to a controller. The controller does a db lookup and pulls data that is LIKE '$input%', and returns a json object back to your javascript, which then populates the dropdown with matching choices. There isn't really anything that has to do with CI or MVC here. You're making a request to a controller and returning data, just like anything else. The only difference is you have javascript making the request via ajax. If you would like help with your existing code, post it and I'm sure someone can point you in the right direction with whatever you're having a problem with.
Alternatively, depending on the amount of data you're dealing with, you can supply the possible values for the field in the original response and have the auto-complete functionality entirely handled on the client: http://jqueryui.com/autocomplete/#multiple
The biggest issue you have to look out for in dealing with almost any auto-complete solution in CI is handling AJAX functionality when CSRF protection is enabled on the site, because you have to ensure that you can send the CSRF field/value in the POST, and possibly update the CSRF field/value when sending/handling the response. |
Welcome Guest, Not a member yet? Register Sign In |