Mirko wrote: > ... > Event.observe(domText, "keypress", > this.onKeyPress.bindAsEventListener(this)); > > ... > if (name == 'keypress' && > (Prototype.Browser.WebKit || element.attachEvent)) > name = 'keydown'; > > is not working properly. Anyway, by commenting the test we only fixed > the problem with IE. In order to fix the event handling with Opera, we > had to avoid the bindAsEventListener call: > > Event.observe(domText, "keypress", this.onKeyPress); > > Is it a problem of the prototype library or are we doing something > wrong? > > ... A few things.
1. Keep in mind that a keypress is a keydown plus a keyup. So keydown works well most of the time, BUT keydown cannot be stopped through Event.stop() (see http://www.quirksmode.org/js/events_compinfo.html#keys). So the line where Prototype changes a keypress to a keydown may hinder your goal. I don't know why it would apply to Opera or why it needs to be there at all. 2. There are a lot of quirks for cross-browser key-stroke detection (see http://www.quirksmode.org/js/keys.html). One example is the plus character. 3. It is a lot more user friendly and simpler to attach an onblur event that simply removes disallowed characters. For example: Event.observe(domText, 'blur', function() { if (/\D/.test(domText.value)) { domText.value = domText.value.replace(/\D/g, ''); alert('Only numbers are allowed'); } }); - kds --~--~---------~--~----~------------~-------~--~----~ 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 [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
