I have a simple query/filter widget that via AJAX call updates a results <div> <div id="filter" > <form_remote_tag :update => :results> Search <input>....</input> <submit button> </form> </div> <div id="results> ..table of results </div> When the user enters a value into the search field, clicks submit the ajax does it magic, the controller is called and new results are updated to the results div. All very happy and working well. However inside the filter widget now want another submit button "download to excel" that will pick up the search input values and rather than update the results div with the values, push out a formated table as a spread sheet. In the controller I create a text string and then send it to the browser. mytext = render_to_string( :action => ''list_excel'', :layout => false) send_data mytext, :type => ''application/vnd.ms-excel'', :disposition => ''inline'' I created a "submit_to_remote" link to call a different controller method that will push out the excel <%= submit_to_remote("excel", "excel", :url => { :action => :push_excel :update => :results }, :method => ''post'' ) %> Everything is called correctly but it doesnt work, excel is not called, the reason is that the html headers are not updated thus IE doest know to start excel. How do I inside a AJAX form_remote_tag construct, create a button that when clicked will do the following: a) The controller will have the params of the form available to modify the results(ie the search filter value), I can get excel start with a link_to a different controller but the values of the form are not available (or I dont know how to access or include them in a link_to call) b) Popup, render or send_data or any way to send a full page with the correct headers to have a browser start excel. I hope my question is not to confusing. -- 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 -~----------~----~----~----~------~----~------~--~---
Glenn Cadman wrote:> How do I inside a AJAX form_remote_tag construct, create a button that > when clicked will do the following: > a) The controller will have the params of the form available to modify > the results(ie the search filter value), I can get excel start with a > link_to a different controller but the values of the form are not > available (or I dont know how to access or include them in a link_to > call) > b) Popup, render or send_data or any way to send a full page with the > correct headers to have a browser start excel. > > I hope my question is not to confusing.I dont think you can download a file via javascript. I think your best bet is to render an iframe with the url of your spreadsheet file in it. The browser *should* save thefile or launch the appropriate application when it tries to read the data. -- 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 -~----------~----~----~----~------~----~------~--~---
Glenn Cadman wrote:> How do I inside a AJAX form_remote_tag construct, create a button that > when clicked will do the following: > a) The controller will have the params of the form available to modify > the results(ie the search filter value), I can get excel start with a > link_to a different controller but the values of the form are not > available (or I dont know how to access or include them in a link_to > call) > b) Popup, render or send_data or any way to send a full page with the > correct headers to have a browser start excel.Change the form to a normal form, with its target parameter optionally set to "_blank", and change the AJAX submit to submit_to_remote. -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mark Reginald James wrote:> Glenn Cadman wrote: > >> How do I inside a AJAX form_remote_tag construct, create a button that >> when clicked will do the following: >> a) The controller will have the params of the form available to modify >> the results(ie the search filter value), I can get excel start with a >> link_to a different controller but the values of the form are not >> available (or I dont know how to access or include them in a link_to >> call) >> b) Popup, render or send_data or any way to send a full page with the >> correct headers to have a browser start excel. > > Change the form to a normal form, with its target parameter optionally > set to "_blank", and change the AJAX submit to submit_to_remote. > > -- > We develop, watch us RoR, in numbers too big to ignore.With the submit_to_remote what is the :update target? I just cannot see how the html header will be refreshed? -- 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 -~----------~----~----~----~------~----~------~--~---
Glenn Cadman wrote:> Mark Reginald James wrote: >> Change the form to a normal form, with its target parameter optionally >> set to "_blank", and change the AJAX submit to submit_to_remote. > > With the submit_to_remote what is the :update target? I just cannot see > how the html header will be refreshed?It''s the AJAX search that should be a submit_to_remote. The Excel button should instead be a normal submit button: <%= form_tag({:action => ''search_excel''}, :target => ''_blank'') %> <%= text_field_tag ''terms'' %> <%= submit_to_remote nil, ''Search'', :url => {:action => ''search''}, :update => :results %> <%= submit_tag ''Search and display results in Excel'' %> </form> <div id="results"> ..table of results </div> -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mark Reginald James wrote:> Glenn Cadman wrote: >> Mark Reginald James wrote: >>> Change the form to a normal form, with its target parameter optionally >>> set to "_blank", and change the AJAX submit to submit_to_remote. >> >> With the submit_to_remote what is the :update target? I just cannot see >> how the html header will be refreshed? > > It''s the AJAX search that should be a submit_to_remote. The Excel button > should instead be a normal submit button: > > <%= form_tag({:action => ''search_excel''}, :target => ''_blank'') %> > <%= text_field_tag ''terms'' %> > <%= submit_to_remote nil, ''Search'', :url => {:action => ''search''}, > :update => :results %> > <%= submit_tag ''Search and display results in Excel'' %> > </form> > > <div id="results"> > ..table of results > </div> > > -- > We develop, watch us RoR, in numbers too big to ignore.Mark well, it works, works well!!! I spent close to 10 hours on a very complex javascript solution for this problem (and failed), it always amazes me how elegant ROR solutions are, if only I had the intelligence to think of the solution myself! Rather than a submit_to_remote, I combined everything with an form_observer I have the complete functionality set I wanted to deliver 3 gold "Genius" stars to Mark -- 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 -~----------~----~----~----~------~----~------~--~---
OK I found one issue with the user interface, should the user hit return in the filter wizard (form) he/she will popup a excel sheet and for them this is misterious because they didnt click on the excel button? How can I disable posting if user hits the enter key? -- 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 -~----------~----~----~----~------~----~------~--~---
Glenn Cadman wrote:> OK I found one issue with the user interface, should the user hit return > in the filter wizard (form) he/she will popup a excel sheet and for them > this is misterious because they didnt click on the excel button? > > How can I disable posting if user hits the enter key?Yeah, that''s a bit of fly in the ointment. Here''s one way to switch the enter key from Excel to AJAX search: <%= form_tag({:action => ''search_excel''}, :target => ''_blank'') %> <%= text_field_tag ''terms'', nil, :onkeypress => "return event.keyCode != 13 || ($(''s'').click(),false)" %> <%= submit_to_remote nil, ''Search'', :url => {:action => ''search''}, :update => :results, :html => {:id => ''s''} %> <%= submit_tag ''Search and display results in Excel'' %> </form> -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---