Hi! I''m using date_select. I want to write a js that change the day field based on the month field (if I select october, than the day field has 31 days, if I select september, it changes to 30, and so on...) This is the field generated by dat_select: <select id="entry_entry_date_3i" name="entry[entry_date(3i)]"> I need to target the id with javascript, so I need to abstract it too. I would really like to choose the id by myself... I don''t need "entry_entry_date_3i". I need "year", "month" and "day" (or something similar, not tied to the model), so I can use the js in all my projects. Is there someone that can tell me how to force it? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Oct 28, 5:49 am, Luca Reghellin <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi! > > I''m using date_select. > I want to write a js that change the day field based on the month field > (if I select october, than the day field has 31 days, if I select > september, it changes to 30, and so on...) > > This is the field generated by dat_select: > > <select id="entry_entry_date_3i" name="entry[entry_date(3i)]"> > > I need to target the id with javascript, so I need to abstract it too. I > would really like to choose the id by myself... I don''t need > "entry_entry_date_3i". I need "year", "month" and "day" (or something > similar, not tied to the model), so I can use the js in all my projects. > > Is there someone that can tell me how to force it? > -- > Posted viahttp://www.ruby-forum.com/.The problem with changing the id, or even adding a class or something is that the date_select helper generates multiple select elements (e.g. year, month, day). Have you considered writing some javascript that can create the appropriate id? The id is created as a concatenation of the model, the field, and the subtype of date/times, and the i character, where subtype values are 1 = year, 2 = month, 3 day, and so on for others. If you only cared about having the right number of days for a given month (which is deterministic, but don''t forget about leap years!), you would only need to know the value of model and field, but that''s not really "generic". So a bigger question is, do you really want the default rails date selectors??? If you really, really do, then you might lobby the author of this patch http://dev.rubyonrails.org/attachment/ticket/9015/date_helper.rb to create a patch -- it seems to address exactly what you are looking for (see line 66 of the code compared to the commented out line before it). In short, the date_select fields don''t appear to work like others ... yet. Have you considered a more user-friendly approach, like using one of several calendar helper plugins, such as http://code.google.com/p/calendardateselect/ or http://wiki.rubyonrails.org/rails/pages/Calendar+Helper+Plugin? In addition to ensuring a valid date, they give the user a much nicer interface, in my opinion. Tom --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ok, thank you very much, really deep explanation. I''ll consider all the suggestions. If I''ll choose to write the js anyway, eventually I''ll post it here for whoever need it. thank you very much, Luca tharrison wrote:> On Oct 28, 5:49 am, Luca Reghellin <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> >> I need to target the id with javascript, so I need to abstract it too. I >> would really like to choose the id by myself... I don''t need >> "entry_entry_date_3i". I need "year", "month" and "day" (or something >> similar, not tied to the model), so I can use the js in all my projects. >> >> Is there someone that can tell me how to force it? >> -- >> Posted viahttp://www.ruby-forum.com/. > > The problem with changing the id, or even adding a class or something > is that the date_select helper generates multiple select elements > (e.g. year, month, day). Have you considered writing some javascript > that can create the appropriate id? The id is created as a > concatenation of the model, the field, and the subtype of date/times, > and the i character, where subtype values are 1 = year, 2 = month, 3 > day, and so on for others. If you only cared about having the right > number of days for a given month (which is deterministic, but don''t > forget about leap years!), you would only need to know the value of > model and field, but that''s not really "generic". > > So a bigger question is, do you really want the default rails date > selectors??? If you really, really do, then you might lobby the > author of this patch > http://dev.rubyonrails.org/attachment/ticket/9015/date_helper.rb > to create a patch -- it seems to address exactly what you are looking > for (see line 66 of the code compared to the commented out line before > it). In short, the date_select fields don''t appear to work like > others ... yet. > > Have you considered a more user-friendly approach, like using one of > several calendar helper plugins, such as > http://code.google.com/p/calendardateselect/ > or http://wiki.rubyonrails.org/rails/pages/Calendar+Helper+Plugin? In > addition to ensuring a valid date, they give the user a much nicer > interface, in my opinion. > > Tom-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---