Topic: Form Reset

It seems like the tried and true page['form_id'].reset function no longer works.

What is the best way to reset my form after applying some AJAX?

I checked out this thread but none of the proposed solutions are working.

Ideas?

Re: Form Reset

page[].reset should still be the best way..
gues it's part of your ajax return?
  if yes: what does the ajax call return?
  if no:  try $('form_id').reset(); directly

if you got an url i would check it out...

Re: Form Reset

I'm still in dev mode on this one..so no URL

The good news is that It works fine with the inline JS like so

:success => "$('rlinkform').reset();"

I wish the RJS reset wasnt pooping out on me, but whatever.. at least this works!

Thanks ehdoranil, and welcome to Rails forum smile

Re: Form Reset

thanks for the welcome.

if the application works - great smile
however it would intrigue me what ajax now does return. the code should be pretty much the same, so i wonder where rjs got trouble...

regards

Re: Form Reset

I'm not sure why, but now its working with RJS.,,same syntax and all. Go figure

The only thing I would probably want to refactor at this point would be the callbacks.

Right now my form is littered with

:loading => "Element.show('ajax_progress')", :complete => "Element.hide('ajax_progress')", :success => "Element.show('flash_notice');"

Can this stuff go into RJS as well?

Re: Form Reset

You could make a few helper methods if you have the same thing over and over.  You could put this in your application helper and use it in multiple views.

 def show_ajax_progress
   "Element.show('ajax_progress')"
end

def hide_ajax_progress
   "Element.hide('ajax_progress')"
end

def show_flash_notice
   "Element.show('flash_notice');"
end


:loading => show_ajax_progress, :complete => hide_ajax_progress, :success => show_flash_notice

Re: Form Reset

Thats a great idea Eric

cheers!