Hi Folks, below is an idea of a Form controller that can be used to add tab ordering and submit behavior to any group of elements:
Form.Controller = Class.create({ initialize: function(form,options) { expect_defined(form,'form'); this.options = Object.extend({ tabOrder: [], onSubmit: Prototype.emtpyFunction },options||{}); $ (form).observe('keypress',this.on_keypress.bindAsEventListener(this)); var on_focus = this.on_focus.bindAsEventListener(this); this.options.taborder.each(function(el){ $(el).observe('focus',on_focus); }); }, on_keypress: function(event) { switch(event.keyCode) { case Event.KEY_TAB: if(!this.current_element_id) break; var i = this.options.tabOrder.indexOf(this.current_element_id); if(i < 0 ) break; event.stop(); this.current_element_id = (i == this.options.tabOrder.length - 1)? this.options.tabOrder[0]:this.options.tabOrder[i+1]; $(this.current_element_id).focus(); case Event.KEY_RETURN: event.stop(); if(this.current_element_id) this.options.onSubmit(); break; default: break; } }, on_focus: function(event) { this.current_element_id = Event.element(event).id; } }); --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---