Forum: Ruby on Rails Submit form disappears on second call

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
873a9db33e289b558e89c039629562f5?d=identicon&s=25 James Smith (jmdjmsmith)
on 2007-02-24 13:43
Hello,

I seem to be having a strange problem. I have a form_remote_tag which i
submit using a javascript call:

if(document.forms['myform'].onsubmit()) {
document.forms['myform'].submit(); }

This works great the first time the call is made - however the second
time it doesn't seem to work - the form seems to have disappeared and
have no properties. I then need to refresh the page and it work again,
then doesn't work on the second attempt, again..

Any ideas?

Do i have to reload the page after using ajax to submit a form, in order
to re-use the form?

Thanks for your time
B09a3f6cdc4797532647d2d264b5df49?d=identicon&s=25 Jodi Showers (jshow)
on 2007-02-24 16:10
(Received via mailing list)
James, sounds like you're your :update is writing over your form

look at the partial you're rendering, and the contents, and what div
your rendering too - likely you're rendering to an ID outside the
form_tag, with a partial that doesn't contain the form_tag.

Jodi

On Feb 24, 7:43 am, James Smith <rails-mailing-l...@andreas-s.net>
B09a3f6cdc4797532647d2d264b5df49?d=identicon&s=25 Jodi Showers (jshow)
on 2007-02-24 16:45
(Received via mailing list)
James - on second thought it might be the opposite ( you're rendering
the form_tag twice )

but your best bet, sort of a teach a man to fish, is to pickup
[1]firebug - you'll sleep better.

Jodi
[1]  https://addons.mozilla.org/firefox/1843/
873a9db33e289b558e89c039629562f5?d=identicon&s=25 James Smith (jmdjmsmith)
on 2007-02-24 23:35
> but your best bet, sort of a teach a man to fish, is to pickup
> [1]firebug - you'll sleep better.
>
> Jodi
> [1]  https://addons.mozilla.org/firefox/1843/

Thanks for this, this seems like a great tool.

When i submit the form on the second time i am getting errors in the
console.
The first error is as follows:

this.element has no properties
(no name)(undefined)prototype.js (line 265)
_each(function())prototype.js (line 456)
each(function())prototype.js (line 261)
collect(function())prototype.js (line 293)
invoke("loop")prototype.js (line 349)
loop()effects.js (line 239)
bind()prototype.js (line 48)
[Break on this error] if(this.element.getStyle('display')=='none') {
this.cancel(); return; }

and then the console is repeatedly throwing the following error:

this.element has no properties
[Break on this error] this.element.setStyle({backgroundColor:
$R(0,2).inject('#',function(m,v,i){

and so it keeps going repeatedly throwing the latter error..

So from this i gather that it cannot find the form element.. but then
i'm not sure how i can read further into this and solve my problem, any
ideas?
B09a3f6cdc4797532647d2d264b5df49?d=identicon&s=25 Jodi Showers (jshow)
on 2007-02-26 17:44
(Received via mailing list)
Hey James  - I suggest that it's the first submit that's causing the
problem (symptom) you're seeing, when you try to submit it the second
time.

Follow the logic carefully
  #1. what is the ID that your form result is rendering to? (:update
=> 'id')
  #2. what partial is being rendered by your controller? What is
inside this partial?
  #3. what is currently inside that ID? (on the first render)

I suggest that one of 2 things is happening:
  A. the partial being rendered by the controller (in #2) is rendering
a second form - if this form is inside the current form, or has the
same ID then the Second Form Submit will fail to work
  B. the partial being rendered is not rendering the Form Tag - and so
when you click to submit, the form cannot be found.

this will take some investigation on your part. But if you are careful
you should be able to find out the confusion - and learn a valuable
lesson on the way.

Jodi
On Feb 24, 5:35 pm, James Smith <rails-mailing-l...@andreas-s.net>
873a9db33e289b558e89c039629562f5?d=identicon&s=25 James Smith (jmdjmsmith)
on 2007-02-26 21:09
Finally, i have discovered my wrongs..

I was using effects.js in my rjs file to highlight the form after it had
been submitted, and this was causing the form to effectively disappear.

Why it took me so long to figure out i will never know..

Thanks for your help on this, firebug is a great tool.
This topic is locked and can not be replied to.