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

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
2837408ba0375c40b235f0a5a5107d37?d=identicon&s=25 Doug Livesey (biot023)
on 2006-03-24 13: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?
631d1677786f0725da6ccee46043686e?d=identicon&s=25 Jonathan Viney (Guest)
on 2006-03-24 13: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?')">

36958dd94ca666a38483df282a5214d5?d=identicon&s=25 Peter Ertl (Guest)
on 2006-03-24 13: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?'">
2837408ba0375c40b235f0a5a5107d37?d=identicon&s=25 Doug Livesey (biot023)
on 2006-03-24 15: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}');\" />"

& 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!
This topic is locked and can not be replied to.