Use Algolia to update Django form field

I am trying to use Algolia search results to populate a Django ModelForm field (ie, a ForeignKey) I don’t need to use the form field itself necessarily (ie, drop down) although that would be ideal. I am thinking I’d need to use some javascript to populate the form based on clicking one of the results, but perhaps there is an easier way?)

Hi there!

If you need to add custom behavior when clicking on a search result from your front end, you will indeed need to write some JavaScript.

Assuming you’re using our InstantSearch.js library on your front end, you can set a global event in your code and trigger it when clicking on your element. Here’s a demo to help you get started.

Best,

1 Like