14 Replies Latest reply on Aug 9, 2016 12:36 PM by VectorP

    MWBarcodeScanner

    yohannk19562278

      Hi, i use the MwBarcodeScanner on my phonegap build app

       

      The plugin work correctly, but i need to change the function "callback".

      When i scan a barcode i got an alert with the barecode.

      Me, i need to write the barecode on an input text

       

      I don't really understand the documentation

       

      phonegap-mwbarcodescanner/README.md at 08566953910635c7c0ce9d6cac34160d6681a372 · manateeworks/phonegap-mwbarcodescanner…

       

      for the moment on my app i have just that:

             <script type="text/javascript" src="cordova.js"></script>

              <script type="text/javascript" src="MWBScanner.js"></script>

       

      and the button to launch

       

           <button class="btn waves-effect waves-light deep-orange" onclick="scanner.startScanning()" id="boutoninscription" type="button" name="action">Scanner un article

          <i class="material-icons right">send</i>

      </button>

       

      thanks for the help

        • 1. Re: MWBarcodeScanner
          VectorP Level 4

          Excuse me; do I understand this correctly?

          - you have a barcode scanner plugin implemented

          - the plugin reads a barcode and outputs the code translation in an alert

          - however, you want to write a barcode, based on text in an input field

           

          If the latter is indeed what you want, why did you implement a barcode scanner?

          • 2. Re: MWBarcodeScanner
            yohannk19562278 Level 1

            Hi, its almost that

             

            When i scan the barcode i no want an alert, i want a code like that " $("#myinput").val(BARCODESCANNRETURN); "

             

            i need the barecode scanner on my app

             

            The callback function by default of the plugins is an alert, i want change this callback function

             

            sorry for the english

            • 3. Re: MWBarcodeScanner
              VectorP Level 4

              So, your question is:

               

              "How do I replace the alert in the callback function by $("#myinput").val(BARCODESCANNRETURN);"

               

              ?

              • 4. Re: MWBarcodeScanner
                yohannk19562278 Level 1

                Its that !

                • 5. Re: MWBarcodeScanner
                  VectorP Level 4

                  Perhaps I don't quite understand what you are asking.

                  If it is indeed what is quoted above, then the answer would be:

                   

                  grab your code editor, open the file that contains the callback function, delete the alert and insert that single code line.

                  • 6. Re: MWBarcodeScanner
                    yohannk19562278 Level 1

                    Yes, but my question is how to change this callback function ?

                    • 7. Re: MWBarcodeScanner
                      VectorP Level 4

                      By editing that function in your code editor.

                       

                      Somehow, somewhere, we appear to be misunderstanding each other.

                      As I understand your question:

                      - you know what a callback function is

                      - you know what a code line with an alert statement is

                      - you know that you must replace that line by the jquery code line you quoted

                      ....and now you want to know how to do it? Isn't the answer "use your code editor, then open and edit that file" correct? Did you try it?

                       

                      What am I missing?

                      And if you don't know how to edit that function, would you alternatively consider coding a separate callback function and use that as a callback, instead of the one you apparently don't know how to edit?

                      • 8. Re: MWBarcodeScanner
                        yohannk19562278 Level 1

                        Yes i don't know how to change his function ; i give you a github link on my first POST ;

                         

                        apparently, the point 1.4 on the documentation explain how to change his function ! i try, but i don't understand all

                         

                        if you understand the documentation, can you explain me please?

                        • 9. Re: MWBarcodeScanner
                          VectorP Level 4

                          You will have to add the callback function in file js/MWBConfig.js

                           

                          This is the function. My comments in bold print:

                           

                          //custom callback function, one that can be modified by the user

                          MWBSInitSpace.callback = function(result){

                           

                          //delete next line after having tested:

                              console.log('MWBSInitSpace.callback Invoked at: '+ (new Date()).getTime());

                             

                               /**

                                 * result.code - string representation of barcode result

                                 * result.type - type of barcode detected or 'Cancel' if scanning is canceled

                                 * result.bytes - bytes array of raw barcode result

                                 * result.isGS1 - (boolean) barcode is GS1 compliant

                                 * result.location - contains rectangle points p1,p2,p3,p4 with the corresponding x,y

                                 * result.imageWidth - Width of the scanned image

                                 * result.imageHeight - Height of the scanned image

                                 */

                              

                          //delete next line after having tested:

                              console.log('Scan complete');

                           

                             if (result.type == 'Cancel'){

                                      //Perform some action on scanning canceled if needed

                                      }

                                      else if (result && result.code){

                                        

                                          /*

                                          *  Use this sample if scanning in view

                                          */

                                          /*

                          //You can use the below example, or paste your line of jquery code here. Make sure you remove the comment characters around this piece of code, then:

                                          var para = document.createElement("li");

                                          var node = document.createTextNode(result.code+" : "+result.type);

                                          para.appendChild(node);

                                                       

                                          var element = document.getElementById("mwb_list");

                                          element.appendChild(para);

                                          */         

                           

                           

                                          /*

                                          *  Use this sample when using mwbs['MWBcloseScannerOnDecode'](false);

                                          */

                                          /*

                                           setTimeout(function(){                 

                                              scanner.resumeScanning();  

                                           },2000);                               

                                          */

                           

                          //delete next line after having tested. This is the alert you were talking about:

                                         navigator.notification.alert(result.code, function(){}, result.type + (result.isGS1?" (GS1)":""), 'Close');

                           

                                      }

                          }

                          • 10. Re: MWBarcodeScanner
                            yohannk19562278 Level 1

                            Thanks for the answser!

                             

                            i added a file js/MWBConfig.js with the code

                            added this code on my index.html

                             

                            and on my index i have a button onclick="scanner.startScanning(MWBSInitSpace.init,MWBSInitSpace.callback)"

                             

                            and the scanner doesnt start

                             

                            i have an error? 

                            • 11. Re: MWBarcodeScanner
                              VectorP Level 4

                              Probably.

                              At the time of that call, what is the object type value for 'scanner' and "scanner.startScanning"?

                              If 'undefined', the plugin hasn't been initiated correctly.

                              • 12. Re: MWBarcodeScanner
                                yohannk19562278 Level 1

                                Where you find the value ?

                                • 13. Re: MWBarcodeScanner
                                  yohannk19562278 Level 1

                                  Nobody to help me?

                                  • 14. Re: MWBarcodeScanner
                                    VectorP Level 4

                                    Oh please. If you don't understand a term, why don't you Google it?

                                    In this case: 'javascript display object type '