-
Bug
-
Resolution: Unresolved
-
Normal
-
None
-
8.6.2
-
None
-
None
-
None
Steps to Reproduce
run code locally:
http://zkfiddle.org/sample/4m1op7/3-can-t-run-parallel-barcode-instances
Current Result
first reader will initialize the library and run scans
2nd reader will not have listeners active from library
Expected Result
both reader should be active
Debug Info
this if statement will prevents components to register a reader for themselves if the library was already used in a different component.
At the moment, quagga supports multiple callbacks on same reader, zxing doesn't.
In both cases, only the first barcodereader is allowed to register listeners on the reader object.
This means that if a page adds a reader (in a modal window, or in a template with multiple sources) then removes it, and adds another instance of reader,: only the first reader will actually receive JS library events
Root Cause
Abstraction layers initialize the library once per page, only let the first component actually register a listener
Workaround
<script><![CDATA[ zk.afterLoad('zkmax.barscanner', function() { var xBarcodescanner = {}; zk.override(zkmax.barscanner.Barcodescanner.prototype, xBarcodescanner ,{ _setReaders: function () { var libs = this.$class._checkLibs(this), wgt = this; var wgtLibsName = []; this.libs.forEach(function (lib) { wgtLibsName.push(lib.libname); }); for (var i = 0; i < libs.length; i++) { wgt.$n('canvas').width = wgt.$n('canvas').width; wgt.$n('canvas').height = wgt.$n('canvas').height; var barReader = wgt.$class._readerConstruct(wgt, libs[i].constructor); if (barReader['zinit']) { barReader.zinit(wgt, wgt.$n('video'), wgt.$n('canvas'), wgt.$n()); barReader.zexecute(wgt); } wgt.readers.push(barReader); wgt.libs.push(libs[i]); } } });//zk.override });//zk.afterLoad ]]></script>
- relates to
-
ZK-5230 adding Barcodescanner twice causes javascript errors
- Open