What i’m currently doing here is i want to add a qr code scanner on my personal website (for test purposes only) and im using a Javascript library.
Now the Javascript code that reads and decodes the qr code was defined in assets/js/app.js file. I would want to access this result in my Elixir code so i can use it to scan for records in my database.
You wont be able to directly access the javascript values in Elixir, you need to send them over some bridge. There are a few ways you might approach this. Your QR library will have some way to run a javascript function when a QR code is recognised and this function will all most certainly receive the data that was embedded in the QR code.
In this callback you might:
a) Make a HTTP request in JS to a controller-action that returns data from your records. Your JS should then process the results and update the page for the user. Most commonly this data is returned as JSON.
b) Redirect to a URL with your QR result embedded in the URL. So if your QR code decodes to dogs, you might redirect to https://myapp.com/search?q=dogs to search for dogs, or if it decoded to a record id 100, you might redirect to https://myapp.com/blog/100. This can be as simple as
c) Use the QR data to set values in a regular HTML form and submit it. This an be useful if you have an existing form on the page and the QR code is a “shortcut” to some results from that form.
Would you mind explaining this further please? I have the same issue as the OP and am still new to elixir/phoenix. I’m using Surface UI if it helps to mention that. Thank you