Forum: Ruby on Rails onsubmit for remote_form_for not working properly

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.
C42c706fab23da0b6d3cd2cfbb8db27d?d=identicon&s=25 Salil Gaikwad (salil)
on 2009-03-10 06:20
I want to use onsubmit for a form validation using javascript on
remote_form_for

for this i am doing something like this

<% remote_form_for :timesheet, @timesheet, :url =>{:action =>
'report_user'}, :html => {:onsubmit=>"return ValidateDate();" } do |f|
%>


    // Form elements here


<% end %>

but it not works well. if condition return false then my form is not get
submitted this is exactly what i want but when it returns true it
produce something like this o/p on UI.

Element.update("user_report", "\n\n\u003Ctable class=\"list
issues\"\u003E\n    \u003Cthead\u003E\u003Ctr\u003E\n
\u003Cth\u003E#\u003C/th\u003E\n

when i delete :html code it works fine.

Regards,
Salil
36ed63ef68c172f148c491418395d0b5?d=identicon&s=25 rubyguy@ymail.com (Guest)
on 2009-03-10 08:17
(Received via mailing list)
On 10 Mar., 06:20, Salil Gaikwad <rails-mailing-l...@andreas-s.net>
wrote:
> I want to use onsubmit for a form validation using javascript on
> remote_form_for

<snip>

> but it not works well. if condition return false then my form is not get
> submitted this is exactly what i want but when it returns true it
> produce something like this o/p on UI.
>
> Element.update("user_report", "\n\n\u003Ctable class=\"list
> issues\"\u003E\n    \u003Cthead\u003E\u003Ctr\u003E\n
> \u003Cth\u003E#\u003C/th\u003E\n

I guess this is a JavaScript issue. What about showing us that?
C42c706fab23da0b6d3cd2cfbb8db27d?d=identicon&s=25 Salil Gaikwad (salil)
on 2009-03-10 08:29
>  <% remote_form_for :timesheet, @timesheet, :url =>{:action =>
>  'report_user'}, :html => {:onsubmit=>"return ValidateDate();" } do |f|
>   %>

> I guess this is a JavaScript issue. What about showing us that?

Thanx 4 ur reply

No i am just telling what problem i m facing.
 i just want to know is onsubmit  working properly with remote_form_for?
and  wheather there is any syntax error in my code above ?

Regards,
Salil
36ed63ef68c172f148c491418395d0b5?d=identicon&s=25 rubyguy@ymail.com (Guest)
on 2009-03-17 16:02
(Received via mailing list)
On 10 Mar., 08:29, Salil Gaikwad <rails-mailing-l...@andreas-s.net>
wrote:
> >  <% remote_form_for :timesheet, @timesheet, :url =>{:action =>
> >  'report_user'}, :html => {:onsubmit=>"return ValidateDate();" } do |f|
> >   %>
> > I guess this is a JavaScript issue. What about showing us that?
>
> Thanx 4 ur reply
>
> No i am just telling what problem i m facing.
>  i just want to know is onsubmit  working properly with remote_form_for?
> and  wheather there is any syntax error in my code above ?

No, remote_form_for will use the onsubmit event to make the actual
AJAX request. So I don't think overriding the onsubmit attribute would
be a good idea... :)

--
Cheers,
David Knorr
http://twitter.com/rubyguy
C42c706fab23da0b6d3cd2cfbb8db27d?d=identicon&s=25 Salil Gaikwad (salil)
on 2009-03-17 17:17
> No, remote_form_for will use the onsubmit event to make the actual
> AJAX request. So I don't think overriding the onsubmit attribute would
> be a good idea... :)
>

thanx @David.
Do you know what should do in that case to put javascript form
validations?

Thanx & Regards
Salil
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-17 17:36
(Received via mailing list)
On Mar 17, 4:17 pm, Salil Gaikwad <rails-mailing-l...@andreas-s.net>
wrote:
> > No, remote_form_for will use the onsubmit event to make the actual
> > AJAX request. So I don't think overriding the onsubmit attribute would
> > be a good idea... :)
>
> thanx @David.
> Do you know what should do in that case to put javascript form
> validations?

The ajax helpers can take a :conditions parameter which is a fragment
of javascript to run to check whether the request should go ahead
(it's described in the docs for link_to_remote)

Fred
This topic is locked and can not be replied to.