Forum: Ruby on Rails JS validation on a form/submit tag? Like :condition=>...

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.
Doug L. (Guest)
on 2006-03-24 14:14
Hallo -- is there a way anyone know of that I can add a :confirm clause
to a form submit? Something like:
<%= submit_tag 'commit', :confirm=>"are you certain?" %>
Does anyone know how to achieve this?
Cheers,
   doug.
Jonathan V. (Guest)
on 2006-03-24 14:18
(Received via mailing list)
My guess is that would need to go in the onclick handler for the form.

<form .... onclick="return confirm('Are you sure?')">

-Jonny.
Peter E. (Guest)
on 2006-03-24 14:54
(Received via mailing list)
>From the top of my head I remember this.

However, check it in different browsers first!

 <form onsubmit="return confirm('REaLlY?'">
Doug L. (Guest)
on 2006-03-24 16:31
Hi -- the way I did it was like this:
I created a helper method in 'application_helper.rb':

  def confirm_submit_tag(value="submit", msg="Are you sure?")
    "<input type=\"submit\" value=\"#{value}\" onclick=\"return
confirm('#{msg}');\" />"
  end

& then, in the rhtml (inside the form), I can just use

  <%= confirm_submit_tag 'commit', "This will commit the changes you
made." %>

It works well in firefox & IE.
Cheers for the input!
   doug.
This topic is locked and can not be replied to.