Hi, I have a form with many checkboxes, which names looks like this name=''selectedLine[127][23]'' It is impossible to collect them with Form.getInputs, cause the numbers in brackets are variable. Anyway, all the checkboxes'' names would match RegExp /selectedLine\[\d+\]\[\d+\]/ I suggest adding support for RegExp matching of input names. We can test if the "name" parameter is an RegExp by checking if it implements the "test" and "exec" regExp methods. If so, we use name.test(), else we use old method - direct comparison. Of course it is possible that not-RegExp object will implement test and exec methods, but then, I think it is safe to trust that the programmer knows what (s)he passes to this method. If it is something random, then i wouldn''t made through (name != input.name) comparison either. It is also possible to pass any object with test() method witch would do any test needed, not necessarily an RegExp test. Maybe we even should''n test for .exec() method? This patch works for me: http://swilk.int.pl/form.js-getInputsWithRegExp.diff What do you think? -- Regards, Szymon Wilkołazki --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
This looks interesting, but it seems like current selector abilities can handle such case quite easily: // collect all "input" elements within a form with id "myForm" that are of type "checkbox" and whose name attribute value begins with "selectedLine" : ) $$(''#myForm input[type=checkbox][name^=selectedLine]''); Enumerable methods can do this as well: myForm.getInputs(''checkbox'').findAll(function(el) { return /selectedLine\[\d+\]\[\d+\]/.test(el.name); }) As far as checking whether argument is a regexp - why not just do: object.constructor == RegExp Best, kangax On Apr 16, 7:33 am, SWilk <wilkola...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I have a form with many checkboxes, which names looks like this > > name=''selectedLine[127][23]'' > > It is impossible to collect them with Form.getInputs, cause the > numbers in brackets are variable. > Anyway, all the checkboxes'' names would match RegExp > /selectedLine\[\d+\]\[\d+\]/ > > I suggest adding support for RegExp matching of input names. > > We can test if the "name" parameter is an RegExp by checking if it > implements the "test" and "exec" regExp methods. If so, we use > name.test(), else we use old method - direct comparison. > > Of course it is possible that not-RegExp object will implement test > and exec methods, but then, I think it is safe to trust that the > programmer knows what (s)he passes to this method. If it is something > random, then i wouldn''t made through (name != input.name) comparison > either. > It is also possible to pass any object with test() method witch would > do any test needed, not necessarily an RegExp test. Maybe we even > should''n test for .exec() method? > > This patch works for me:http://swilk.int.pl/form.js-getInputsWithRegExp.diff > > What do you think? > > -- > Regards, > Szymon Wilkołazki--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi, kangax wrote:> This looks interesting, but it seems like current selector abilities > can handle such case quite easily: > > // collect all "input" elements within a form with id "myForm" that > are of type "checkbox" and whose name attribute value begins with > "selectedLine" : ) > > $$(''#myForm input[type=checkbox][name^=selectedLine]''); > > Enumerable methods can do this as well: > > myForm.getInputs(''checkbox'').findAll(function(el) { > return /selectedLine\[\d+\]\[\d+\]/.test(el.name); > })In this job one learns all the time... ;) Thanks for suggestions. I''ve already created a ticket with my patch from previous post on http://prototype.lighthouseapp.com/projects/8886/tickets/18-form-getelement-accept-regexp-additionally-to-string-as-name-parameter ...but now I think that it''s not necessary. The only drawback of that Enumerable.findAll method is that I need to loop again through all the checkboxes collected #myForm (witch in my case could be a few hundreds, about 50% of them are those I need). We''ll see if it is fast enough. Anyway, the less personalized prototype.js the better. I already have one not-yet-in-trunk-if-ever-patch applied, this would be second change used in my production env. It''s not good to have to patch each new prototype release. You could always forgot one little change and something stops working...> > As far as checking whether argument is a regexp - why not just do: > object.constructor == RegExp >yeah... why I have not thought of this? Anyway, I think not testing if the passed object is exactly a RegExp has one advantage: One could pass a simple object with test() method which could provide a custom test. But again, its easier done with findAll... Thanks for pointing me to simple solution, -- Szymon Wilkolazki --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---