I have the following three items in the db: :year_made # a value between 1980 and Time.now.year :year_imported # "Local" or a value between :year_made and Time.now.year :year_registered #If :year_imported == "Local" # a value between :year_made and Time.now.year #else # a value between :year_imported and Time.now.year #end I am trying to build drop downs which follow these rules and am running into difficulties. Any help in building these where they work both in new and edit action (with the correct value as saved in db preselected will be greatly appreciated) -- Posted via ruby-forum.com.
Do I need to provide more information for someone to look into this and help me? -- Posted via ruby-forum.com.
On Fri, Aug 28, 2009 at 11:28 PM, Quee Mm<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Do I need to provide more information for someone to look into this and > help me?"more information"? I didn''t see *any* information -- where''s the code you''ve tried that isn''t producing the result you want? -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan
man i have so many different combos but here is my latest code. In my view I have <code> <%= f.select(:year_made, ((1980..Time.now.year).collect {|p| [ p, p ]}).reverse, {:prompt=>"Select a Year"}) %> <%= f.select(:year_imported, ((1980..Time.now.year).collect {|p| [ p, p ]}).reverse, :prompt=>"Select a Year") %> <%= f.select(:year_registered, ((1980..Time.now.year).collect {|p| [ p, p ]}).reverse, :prompt=>"Select a Year") %> </code> then i am using JavaScript to control what the drop downs will show.. <code> jQuery(''#vehicle_year_made'').change(function(){ year_made_id = jQuery("#vehicle_year_made :selected").val(); if (year_made_id != "" ) { var currentTime = new Date() var options = ''<option>Select a Year</option><option value="Local">Local</option>''; for (i=currentTime.getFullYear(); i >= year_made_id; i--) { options += ''<option value="'' + i + ''">'' + i + ''</option>''; } jQuery("#vehicle_year_imported").html(options); jQuery("#vehicle_year_imported").removeAttr("disabled"); jQuery(''#vehicle_year_imported'').change(function(){ if ( jQuery("#vehicle_year_imported :selected").val() == "" || jQuery("#vehicle_year_imported :selected").val() == "Select a Year") { jQuery("#vehicle_year_registered").attr("disabled", "disabled"); } year_import_id = jQuery("#vehicle_year_imported :selected").val(); if (year_import_id != "Select a Year" && year_import_id != "Local") { var options = ''<option>Select a Year</option><option value="Un-Registered">Un-Registered</option>''; for (i=currentTime.getFullYear(); i >= year_import_id; i--) { options += ''<option value="'' + i + ''">'' + i + ''</option>''; } jQuery("#vehicle_year_registered").html(options); if (options != ''<option>Select a Year</option>'') { jQuery("#vehicle_year_registered").removeAttr("disabled"); } } else if (year_import_id == "Local") { var options = ''<option>Select a Year</option><option value="Un-Registered">Un-Registered</option>''; for (i=currentTime.getFullYear(); i >= year_made_id; i--) { options += ''<option value="'' + i + ''">'' + i + ''</option>''; } jQuery("#vehicle_year_registered").html(options); if (options != ''<option>Select a Year</option>'') { jQuery("#vehicle_year_registered").removeAttr("disabled"); } } else { options = ''<option>Select a Year</option>''; jQuery("#vehicle_year_registered").html(options); jQuery("#vehicle_year_registered").attr("disabled", "disabled"); } }); } else { options = ''<option>Select a Year</option>''; jQuery("#vehicle_year_imported").html(options); jQuery("#vehicle_year_imported").attr("disabled", "disabled"); jQuery("#vehicle_year_registered").html(options); jQuery("#vehicle_year_registered").attr("disabled", "disabled"); } }); </code> This works perfectly fine at new but when i edit a record the JavaScript does not seem to work and all drop downs show 2009 - 1980 as options. -- Posted via ruby-forum.com.
Hey can you please use some service like pastie.org to paste the code and give us the link ? Reading this code gives me a headache ... Thanks & Regards, Dhruva Sagar. Jonathan Swift<brainyquote.com/quotes/authors/j/jonathan_swift.html> - "May you live every day of your life." On Sat, Aug 29, 2009 at 1:39 PM, Quee Mm <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > man i have so many different combos but here is my latest code. > > In my view I have > <code> > <%= f.select(:year_made, ((1980..Time.now.year).collect {|p| [ p, p > ]}).reverse, {:prompt=>"Select a Year"}) %> > <%= f.select(:year_imported, ((1980..Time.now.year).collect {|p| [ p, p > ]}).reverse, :prompt=>"Select a Year") %> > <%= f.select(:year_registered, ((1980..Time.now.year).collect {|p| [ p, > p ]}).reverse, :prompt=>"Select a Year") %> > </code> > then i am using JavaScript to control what the drop downs will show.. > <code> > jQuery(''#vehicle_year_made'').change(function(){ > year_made_id = jQuery("#vehicle_year_made :selected").val(); > if (year_made_id != "" ) { > var currentTime = new Date() > var options = ''<option>Select a Year</option><option > value="Local">Local</option>''; > for (i=currentTime.getFullYear(); i >= year_made_id; i--) { > options += ''<option value="'' + i + ''">'' + i + ''</option>''; > } > jQuery("#vehicle_year_imported").html(options); > jQuery("#vehicle_year_imported").removeAttr("disabled"); > > jQuery(''#vehicle_year_imported'').change(function(){ > if ( jQuery("#vehicle_year_imported :selected").val() == "" || > jQuery("#vehicle_year_imported :selected").val() == "Select a Year") > { > jQuery("#vehicle_year_registered").attr("disabled", > "disabled"); > } > year_import_id = jQuery("#vehicle_year_imported > :selected").val(); > if (year_import_id != "Select a Year" && year_import_id !> "Local") { > var options = ''<option>Select a Year</option><option > value="Un-Registered">Un-Registered</option>''; > for (i=currentTime.getFullYear(); i >= year_import_id; i--) { > options += ''<option value="'' + i + ''">'' + i + ''</option>''; > } > jQuery("#vehicle_year_registered").html(options); > if (options != ''<option>Select a Year</option>'') { > jQuery("#vehicle_year_registered").removeAttr("disabled"); > } > } > else if (year_import_id == "Local") { > var options = ''<option>Select a Year</option><option > value="Un-Registered">Un-Registered</option>''; > for (i=currentTime.getFullYear(); i >= year_made_id; i--) { > options += ''<option value="'' + i + ''">'' + i + ''</option>''; > } > jQuery("#vehicle_year_registered").html(options); > if (options != ''<option>Select a Year</option>'') { > jQuery("#vehicle_year_registered").removeAttr("disabled"); > } > } > else > { > options = ''<option>Select a Year</option>''; > jQuery("#vehicle_year_registered").html(options); > jQuery("#vehicle_year_registered").attr("disabled", > "disabled"); > } > }); > > } > else > { > options = ''<option>Select a Year</option>''; > jQuery("#vehicle_year_imported").html(options); > jQuery("#vehicle_year_imported").attr("disabled", "disabled"); > jQuery("#vehicle_year_registered").html(options); > jQuery("#vehicle_year_registered").attr("disabled", "disabled"); > } > }); > </code> > > This works perfectly fine at new but when i edit a record the JavaScript > does not seem to work and all drop downs show 2009 - 1980 as options. > -- > Posted via 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Well this is my first time working with pastie and all so please bear with me. Here is the link to the pastie. pastie.org/private/uaaeocr2866tke49sg thanks for looking into this. Regards, Quee -- Posted via ruby-forum.com.
On Sat, Aug 29, 2009 at 1:09 AM, Quee Mm<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> <code> > <%= f.select(:year_made, ((1980..Time.now.year).collect {|p| [ p, p > ]}).reverse, {:prompt=>"Select a Year"}) %> > <%= f.select(:year_imported, ((1980..Time.now.year).collect {|p| [ p, p > ]}).reverse, :prompt=>"Select a Year") %> > <%= f.select(:year_registered, ((1980..Time.now.year).collect {|p| [ p, > p ]}).reverse, :prompt=>"Select a Year") %> > </code>If you look at this with syntax highlighting, like in your pastie, you''ll see there''s a difference in the code for the first vs second and third. May not be the issue but...> then i am using JavaScript to control what the drop downs will show..I would first disable JavaScript and make sure the selects are being generated with the initial values you want. Then, if this is strictly a JS issue (and it fails in Firefox) you can use Firebug to troubleshoot the problem. -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan
The code works fine and does generate the three drop downs i think I am missing the point where I can tell the code what the already :selected value is. As i already said, when i do a new record, the code and the javascript work just fine and give me the results that i need, now the edit is a different story, for that all i get is three drop downs with 1980 - 2009 as options in all three fields and it seems as if the javascript is not present. -- Posted via ruby-forum.com.
On Sat, Aug 29, 2009 at 9:24 AM, Quee Mm<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> .... for that all i get is three drop downs with 1980 - 2009 > as options in all three fields and it seems as if the javascript is not > present...which usually indicates a JS error; are you using Firefox with Firebug? If not, why not? Or at least wrap your code in a try/catch block and alert any error. -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan
I would like to tell you one small thing. You don''t need :selected in any of the val() calls. for a select box, the val() method is wise enough to return the selected value. Thanks & Regards, Dhruva Sagar. Joan Crawford<brainyquote.com/quotes/authors/j/joan_crawford.html> - "I, Joan Crawford, I believe in the dollar. Everything I earn, I spend." On Sat, Aug 29, 2009 at 9:54 PM, Quee Mm <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > The code works fine and does generate the three drop downs i think I am > missing the point where I can tell the code what the already :selected > value is. > > As i already said, when i do a new record, the code and the javascript > work just fine and give me the results that i need, now the edit is a > different story, for that all i get is three drop downs with 1980 - 2009 > as options in all three fields and it seems as if the javascript is not > present. > -- > Posted via 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks guys for the pointers, am working on them to see if something comes up. -- Posted via ruby-forum.com.