Signal.connect($CF, "postInit", {c: function() { var cardScan = false; var ccNumber = $(''searchCriteria.creditCardNumber''); var ticketBarcode = $(''searchCriteria.ticketBarCode''); function listenForScan(event) { this.controlKey = event.ctrlKey; if (this.controlKey && event.keyCode == 220) { ccNumber.focus(); cardScan = true; this.controlKey = false; } else if (!cardScan && event.keyCode == 48) { ticketBarcode.focus(); } } Event.observe(document, "keydown", listenForScan.bindAsEventListener(document)); Event.observe(ccNumber, "change", formSubmit.bindAsEventListener(ccNumber)); Event.observe(ticketBarcode, "change", formSubmit.bindAsEventListener(ticketBarcode)); function fillCardInfoFromScan(scanInfo) { var segments = scanInfo.match(/;(\d+)=(\d{2})(\d{2})/); if (segments == null || segments.length < 2){ alert("Invalid Scan"); } else { ccNumber.value = segments[1]; } function formSubmit() { if (cardScan) { fillCardInfoFromScan(ccNumber.value); cardScan = false; } document.<portlet:namespace/>form.submit(); } }}, "c", {before:true}); I have two text fields on my page and i am listening for scans. If its a card scan, i am grabbing the scan value, fitering the card number from scanned value, filling the cardnumber text field and submitting the form. If its an barcode scan i am filling the barcode text field and submitting the form. So i have eventListener (for keydown) on my document which will bring the respective field in focus depending on the scan (card or barcode) and i have eventListeners (for change) on my text fields which will submit the form on value change. The above code works fine on firefox but in IE6 once i scan i have to click anywhere on the page to trigger onChange event for the text field. Is there any way to implement this on IE6 ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
desiwave wrote:> ... > Event.observe(document, "keydown", > listenForScan.bindAsEventListener(document)); > ... > Is there any way to implement this on IE6 ? >I have implemented a BarcodeListener JavaScript class on a production site. I discovered that globally detecting keypress on IE6 requires that you observe _document.body_ instead of _document_ or _window_. So I do: Event.observe( Prototype.Browser.IE ? document.body : window, ''keypress'', listenForScan.bindAsEventListener(document) ); which fires for any keypress in IE6, IE7, FF2 If you have other problems with detecting barcodes in JS, I''d be happy to share my BarcodeListener widget. Regards, Ken Snyder --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Thanx Ken, The scan listening is working fine for my page. The scan value is gettin filled in the repective text fields. If its a card scan i have to process the scan output, filter and grab the card number, change the text field value and then submit the form. If its a barcode scan, i have change the text field value and submit the form. Event.observe(document, "keydown", listenForScan.bindAsEventListener(document)); ---- will bring the corresponding field in focus. Event.observe(ccNumber, "change", formSubmit.bindAsEventListener(ccNumber)); Event.observe(ticketBarcode, "change", formSubmit.bindAsEventListener(ticketBarcode)); ----will submit the form after value change. As you can see in the code I am listening "change" event on the text fields. So after scanning, the field values will change (and i am using this change event to trigger formSubmit). the "listenForScan" and "formSubmit" should get triggered simultaneously without any user input. It works on firefox but not on IE6. I hope i was able to explain the issue clearly.... And again i really appreciate the help.... Vishal On Jul 5, 2:01 pm, Ken Snyder <kendsny...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> desiwave wrote: > > ... > > Event.observe(document, "keydown", > > listenForScan.bindAsEventListener(document)); > > ... > > Is there any way to implement this on IE6 ? > > I have implemented a BarcodeListener JavaScript class on a production > site. I discovered that globally detecting keypress on IE6 requires > that you observe _document.body_ instead of _document_ or _window_. So > I do: > > Event.observe( > Prototype.Browser.IE ? document.body : window, > ''keypress'', > listenForScan.bindAsEventListener(document) > ); > > which fires for any keypress in IE6, IE7, FF2 > > If you have other problems with detecting barcodes in JS, I''d be happy > to share my BarcodeListener widget. > > Regards, > > Ken Snyder--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
desiwave wrote:> ... > Event.observe(ticketBarcode, "change", > formSubmit.bindAsEventListener(ticketBarcode)); > ----will submit the form after value change. > > As you can see in the code I am listening "change" event on the text > fields. So after scanning, the field values will change (and i am > using this change event to trigger formSubmit). the "listenForScan" > and "formSubmit" should get triggered simultaneously without any user > input. It works on firefox but not on IE6. > ...So the onchange isn''t firing properly in IE6. I seem to have had it in my mind that IE6 only supported onchange for selects, but a google search of "onchange IE6" seems to indicate otherwise. I know I''ve had trouble with onchange for inputs on IE6 and I just avoid them. What happens when you attach the function to the ticketBarcode element inline? My BarcodeListener widget takes another approach altogether. It listens for keypresses, then waits for a break of at least 250ms (I discovered that USB barcode readers typically fire the keypress event about 20ms apart for each character). After any such break, it checks all the registered regexes and executes the corresponding registered functions for matches. That way, it doesn''t need to use inputs to capture the barcode string. -- Ken --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---