Hi all, I''m just wondering if there''s a way to enumerate a form''s input fields (and selects and etc) in tab order. Is there a standard or a prototypish way to do this? Anthyon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Not really tested but something like this should get you started: $(''my_form'').getElements().sortBy(function(element) { return parseInt(element.readAttribute(''tabindex'') || 0); }).each(function(element) { // do something }); /Martin 2008/5/22 anthyon <anthyon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > Hi all, > > I''m just wondering if there''s a way to enumerate a form''s input fields > (and selects and etc) in tab order. Is there a standard or a > prototypish way to do this? > > Anthyon > > >-- burnfield.com/martin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
i tried what you mentioned, but i have a problem with the "0" in the sortby. the elements in the collection without tabindex are returned in a random way, instead of in document order. :( looking at the Form#getElements method it says: "getElements(formElement) -> array" -> which i suppose to mean is ordered "Returns a collection..." -> which is not ensured to be ordered so if this method returns ordered list, then i just have to reindex the elements with tabindex. but if not, how can i find out easily the document order of elements? Anthyon Martin Ström írta:> Not really tested but something like this should get you started: > > $(''my_form'').getElements().sortBy(function(element) { > return parseInt(element.readAttribute(''tabindex'') || 0); > }).each(function(element) { > // do something > }); > > /Martin > > 2008/5/22 anthyon <anthyon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > Hi all, > > > > I''m just wondering if there''s a way to enumerate a form''s input fields > > (and selects and etc) in tab order. Is there a standard or a > > prototypish way to do this? > > > > Anthyon > > > > > > > > > -- > burnfield.com/martin--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Add X where X is a arbitary value greater than or equal to the number of elements that are in your form that don''t have tabindexes to the tabindex value in the read attribute call. Then, keep a variable, initialized to 0 before the call, that is going to be the ''fake'' tabindex for the elements that don''t have one. This will ensure the elements are sorted by the order they''re returned by the getElement call when they don''t have a tab index. I can''t guaruntee this will be document order though. Code sample below. var fakeTabIndex = 0; var tabIndexOffset = 100; $(''my_form'').getElements().sortBy(function(element) { return parseInt(element.readAttribute(''tabindex'')+tabIndexOffset || (fakeTabIndex++)); }).each(function(element) { // do something }); On Fri, May 23, 2008 at 1:58 AM, anthyon <anthyon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > i tried what you mentioned, but i have a problem with the "0" in the > sortby. the elements in the collection without tabindex are returned > in a random way, instead of in document order. :( > > looking at the Form#getElements method it says: > > "getElements(formElement) -> array" -> which i suppose to mean is > ordered > "Returns a collection..." -> which is not ensured to be ordered > > so if this method returns ordered list, then i just have to reindex > the elements with tabindex. > > but if not, how can i find out easily the document order of elements? > > Anthyon > > Martin Ström írta: > > Not really tested but something like this should get you started: > > > > $(''my_form'').getElements().sortBy(function(element) { > > return parseInt(element.readAttribute(''tabindex'') || 0); > > }).each(function(element) { > > // do something > > }); > > > > /Martin > > > > 2008/5/22 anthyon <anthyon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > > Hi all, > > > > > > I''m just wondering if there''s a way to enumerate a form''s input fields > > > (and selects and etc) in tab order. Is there a standard or a > > > prototypish way to do this? > > > > > > Anthyon > > > > > > > > > > > > > > > -- > > burnfield.com/martin > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
well i tried this out, and all it proved is that getElement returns a random ordered list. :( i wanted to do this feature independent of the form itself, but as most of my forms are generated dynamically, i will simply generate a tabIndex attribute on each element. In the future i would like to implement an "xforms repeat"-like functionality, and then i will have to be aware of the maxcount of each repeat but that''s not so hard i think. so thanks for all the replies. :) Anthyon Gareth Evans írta:> Add X where X is a arbitary value greater than or equal to the number of > elements that are in your form that don''t have tabindexes to the tabindex > value in the read attribute call. > Then, keep a variable, initialized to 0 before the call, that is going to be > the ''fake'' tabindex for the elements that don''t have one. > This will ensure the elements are sorted by the order they''re returned by > the getElement call when they don''t have a tab index. > I can''t guaruntee this will be document order though. > Code sample below. > var fakeTabIndex = 0; > var tabIndexOffset = 100; > $(''my_form'').getElements().sortBy(function(element) { > return parseInt(element.readAttribute(''tabindex'')+tabIndexOffset || > (fakeTabIndex++)); > }).each(function(element) { > // do something > }); >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---