There has to be a better way to do this. What I am trying is not working, and seems convoluted. Essentially, a controller method is called, and exits by rendering a partial the purpose of which is to simply clear a textbox in the view. So I am calling the partial which established the textbox -- but it doesn''t work (i.e. it doesn''t clear the textbox). Does anyone know of a simpler way to do this that might work? Thanks, RVic, partial below: <input id="channel_channelnote_note" name="channel[channelnote_note]" size="15" type="text" value="" onKeyUp="txtBox_onChange(this);" onClick="txtBox_onChange(this);"/> <div class="auto_complete" id="channel_channelnote_note_auto_complete"></div> <script type="text/javascript"> //<![CDATA[ var channel_channelnote_note_auto_completer = new Ajax.Autocompleter(''channel_channelnote_note'', ''channel_channelnote_note_auto_complete'', ''/channelnotes.js'', {method:''get'', paramName:''search''}) //]]> </script> <%= observe_field ''channel_channelnote_note'', :url => {:controller => :channels, :action => ''notesboxchange'' }, :with => "''channelnotes='' + value" %> <script> var textbox = document.getElementByName(''channel[channelnote_note]''); textbox.value=""; </script> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/7a1776d7-75ff-4287-9214-ff3c1294f8da%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
On Nov 14, 2013, at 7:41 AM, RVic wrote:> There has to be a better way to do this. What I am trying is not working, and seems convoluted. Essentially, a controller method is called, and exits by rendering a partial the purpose of which is to simply clear a textbox in the view. So I am calling the partial which established the textbox -- but it doesn''t work (i.e. it doesn''t clear the textbox). Does anyone know of a simpler way to do this that might work? Thanks, RVic, partial below:I''ve read through this explanation and the code below twice, and I''m no closer to figuring out what you mean here. Can you give a slightly higher level explanation of what you''re after here? I will be happy to help, but I don''t understand what the trigger event needs to be to make the text field clear. You may be able to do all of this in JavaScript, or in a callback to another function (again, in JavaScript) that is doing the primary thing to make it necessary to clear this field. So tell me a story like this: When the foo picker is set to baz, clear the bar text field. Something like that, except what you really want. Walter> > > <input id="channel_channelnote_note" name="channel[channelnote_note]" size="15" type="text" value="" onKeyUp="txtBox_onChange(this);" onClick="txtBox_onChange(this);"/> > > <div class="auto_complete" id="channel_channelnote_note_auto_complete"></div> > > <script type="text/javascript"> > //<![CDATA[ > var channel_channelnote_note_auto_completer = new Ajax.Autocompleter(''channel_channelnote_note'', ''channel_channelnote_note_auto_complete'', ''/channelnotes.js'', {method:''get'', paramName:''search''}) > //]]> > </script> > > <%= observe_field ''channel_channelnote_note'', :url => {:controller => :channels, :action => ''notesboxchange'' }, :with => "''channelnotes='' + value" %> > <script> > var textbox = document.getElementByName(''channel[channelnote_note]''); > textbox.value=""; > </script> > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/7a1776d7-75ff-4287-9214-ff3c1294f8da%40googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/79F68399-F59A-46D5-A6A4-6D04419C9462%40wdstudio.com. For more options, visit https://groups.google.com/groups/opt_out.
Thanks Walter, and sorry for the confusion! I have a textbox, on a page that also has a table that is constantly changing via AJAX. (So I dont want to just submit a form here) Also on the page are some buttons. When the buttons are invoked a method in the controller is called (which uses the value in the textbox), and when the method exits, I need to clear the value in the texbox. I am trying to do this all in the partial -- both in the <input....value="" field as well as the javascript at the end of the partial which I assume is invoked as soon as the partial is loaded. Neither method seems to work, the partial is called when the buttons are clicked, the value in the textbox remains. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4639e817-7310-46c5-befc-261896bed6f3%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
On Nov 14, 2013, at 8:43 AM, RVic wrote:> Thanks Walter, and sorry for the confusion! > > I have a textbox, on a page that also has a table that is constantly changing via AJAX. (So I dont want to just submit a form here) > > Also on the page are some buttons. When the buttons are invoked a method in the controller is called (which uses the value in the textbox), and when the method exits, I need to clear the value in the texbox. > > I am trying to do this all in the partial -- both in the <input....value="" field as well as the javascript at the end of the partial which I assume is invoked as soon as the partial is loaded. Neither method seems to work, the partial is called when the buttons are clicked, the value in the textbox remains.I don''t know if/how this flag gets set in a jQuery Ajax request, but in Prototype, unless your entire response is in JavaScript (and thus is implicitly eval''d) you have to set a flag in the initial request to evaluate any inline scripts in the returned HTML content: new Ajax.Updater(''table'', ''/path/to/method'', { evalScripts: true }); If you enable that, then you can do something like this, inline after your table code is updated: <table id="table"> ... </table> <script type="text/javascript"> $(''text_field'').clear(); </script> The other way to do this is to return all of the data as JSON, and update the table and clear the field in one function in the base page. Does that help? Walter> > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4639e817-7310-46c5-befc-261896bed6f3%40googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/360CC91F-C431-4584-8A83-6CAC8052CECA%40wdstudio.com. For more options, visit https://groups.google.com/groups/opt_out.
Walter, No, it occurs independent of the table actually. The Ajax that is in the page is not really even a aprt of the Rails app -- it is json string fed to a peice of javascript on a timer that simply parses it into the table. The textfield, and having it clear when buttons invoke a rails controller method, is a different stunt I am trying to accomplish on the same page (independent of the ajax-driven table). Thanks. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1fed9010-ec39-4f4c-823c-e5089e268b95%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Can you post a cut-down example on a jsfiddle? Walter On Nov 14, 2013, at 9:09 AM, RVic wrote:> Walter, > > No, it occurs independent of the table actually. The Ajax that is in the page is not really even a aprt of the Rails app -- it is json string fed to a peice of javascript on a timer that simply parses it into the table. The textfield, and having it clear when buttons invoke a rails controller method, is a different stunt I am trying to accomplish on the same page (independent of the ajax-driven table). Thanks. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1fed9010-ec39-4f4c-823c-e5089e268b95%40googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/59EA7B7F-174D-4BB5-BA08-E1D34EF3BCB0%40wdstudio.com. For more options, visit https://groups.google.com/groups/opt_out.
On Thu, Nov 14, 2013 at 6:09 AM, RVic <rvince99-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> having it clear when buttons invoke a rails controller methodEarlier you said "... when the method exits, I need to clear the value in the texbox." Which is it? If the former, and the result of the controller action is irrelevant to the clear action, just set the value of the textbox to an empty string on the click event -- simple, client-side. -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yDyLjVMdp-m3L%3DqAqVtzpHFVSSP2J2uaev%2BmuV9u%3Dv1Mg%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
I got it working by wrapping it as a CDATA in the partial, and making sure to put the ''s'' in getElementsByName! Has anyone ever worked out how to get javascript to re-execute on a reload event? Thanks for all your help with this guys. <script type="text/javascript"> //<![CDATA[ var channel_channelnote_note_auto_completer = new Ajax.Autocompleter(''channel_channelnote_note'', ''channel_channelnote_note_auto_complete'', ''/channelnotes.js'', {method:''get'', paramName:''search''}); var textbox = document.getElementsByName(''channel[channelnote_note]'')[0]; textbox.value=""; //]]> </script> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/28b5701f-04ea-4caa-8f12-f57ad71b24a6%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
On Nov 14, 2013, at 12:00 PM, RVic wrote:> Has anyone ever worked out how to get javascript to re-execute on a reload event? Thanks for all your help with this guys.document.addEventListener(''DOMSubtreeModified'', function(){ // do whatever here // beware infinite loops if your callback modifies the DOM }); Walter -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/041B4929-FC2A-4FFB-964B-627981C6718B%40wdstudio.com. For more options, visit https://groups.google.com/groups/opt_out.
Walter, That''s very cool -- but, how would i avoid an infinite loop? If I am clearing out an item that is an element of the DOM, withing your method, it will recurseively call it -- how to prevent that -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4138d5ae-6fea-49f6-9c04-a97521f75596%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
set a condition on your method, fail early. if(elm.value == '''') return; Walter On Nov 14, 2013, at 1:24 PM, RVic wrote:> > Walter, > > That''s very cool -- but, how would i avoid an infinite loop? If I am clearing out an item that is an element of the DOM, withing your method, it will recurseively call it -- how to prevent that > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4138d5ae-6fea-49f6-9c04-a97521f75596%40googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/19AD2D3A-8C61-48AC-93C8-CF305CABD319%40wdstudio.com. For more options, visit https://groups.google.com/groups/opt_out.