Accessing Repeater field from JS code in view
Hi fellows, I have a basic form like this:
This render QRCode scanner preview window. Here I use https://unpkg.com/[email protected]/html5-qrcode.min.js libary and it works liek expected. Problem I having is could not find a way from this view to access the repeater and add scanned code.
using this call to getElementById I have access to temporary input I'm using for debug, but how can I access repeater and add elements from here? Or mayne I could try other approach? Tanks in advance for your answers

Solution:Jump to solution
Hi, I think finally get it working. Added wire:ignore and now qr-scanner is not dissapearing after $wire.dispatchFormEvent('addItem', $data);
```
<div class="mt-6" name="{{ $getName() }}" id="{{ $getId() }}"
wire:ignore...
10 Replies
I think you can work with alpine in your custom view field:
Register a listener in your repeater to add a new item to the repeater state:
Hi @LeandroFerreira thanks a lot for the tip. Have it working partially. Had to adapt like this:
This way I can handle Repeater json/array handling on php side. But having another don't know if related problem. After succefull scan, $wire.dispatchFormEvent('addItem', $data); is called and I can aff item, no problem. But QR code reader just disappears, js code added by the lib is just cleared. If I comment the call to $wire.dispatchFormEvent('addItem', $data); scanner continues showinf without any problem. But this only happends with this custom qr field, If I add some text inputs or any other input it still present after calling $wire.dispatchFormEvent('addItem', $data);. Thanks a lot for your help


Hi, update for this issue. I've trying differents approachs, but everything fails. I just changed repeater control for a simple texarea using registerListeners mechanism to add scaned line to texarea. Behaviour is the same, after first scan, line is added to textarea but qr-code field just dissapears. Is like it is reloading form/section and js component just dissapears. Any workaround could try? Thanks in advance
I’m not 💯 sure on this but it sounds like a livewire dom diffing issuing. Ie, the state is either handled in the js or the php, but it feels like the state is getting out of sync by not ignoring and setting it via one or the other. If that makes sense.
Yep, I think something like that as well. DOM is modified on JS side when creating the qr-view and maybe this modification is not tracked by livewire internals, so when updating it just set DOM like it was before plus modifications made. is ther any workaround? Maybe soe kind of notification to Livewire fro the JS side about the DOM was changed?
I would need to see all of the code to offer more help. Sorry.
Cool, thanks a lot for you help. Code is simple. On field view I just have this:
I was just testing if that wire:key attr could do the trick, but no.
Form definition like:
And addItem function is just:
`
Hope you can have a general overview now, will be here in case you need something else from my side. Really appreciate it
I think the problem maybe your script tag include. That will only initialize on page load. But Lw and alpine work with Ajax requests so the include will never re-init on subsequent requests.
What is the code of your view?
Just this, nothing more
Solution
Hi, I think finally get it working. Added wire:ignore and now qr-scanner is not dissapearing after $wire.dispatchFormEvent('addItem', $data);