On 19 May 2010, at 06:33, badnaam wrote:
I have a form with a select box and there is a div under the select box that gets populated with data collected via ajax, based on the value selected in the select box. I use an observe field to accomplish this. It all work pretty well except, let's say, the form gets submitted (with a value in the select box) and for some reason the validation fails and after the page refresh( the form submission isnt ajax), the select box keeps the value that had been selected, however, since the div underneath only gets populated and shown on a "change" event, is hidden. I would like it to be showing if there is already a value in the select box. one thing I can do is simply make an ajax call when the page loads and populate/show the div, but it would look awkward (the ajax requests show a shadow box type progress bar, this is a requirement). Is there a better way to do this?
Since you have the value in your controller and you simply rerender the same views, make your views more intelligent and render the appropriate data at page render right away.
Bad code, but just so you get the idea <% form_for @record do |f| %> <% f.select :some_id %> ... <% end %> <% if @record && @record.some_id %> render view for value with some_id <% else %> render default view without any value <% end %> Best regards Peter De Berdt -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

