0

Is there an easy way to add a form validation in a Rails app that asks: "Are you sure you want to submit this form with an empty subject?"

(I googled "are you sure" blank rails, validation empty etc. and did not find a useful answer)

borod108
  • 766
  • 1
  • 6
  • 16
  • 1
    http://stackoverflow.com/questions/808547/fully-custom-validation-error-message-with-rails – sjain Apr 02 '13 at 13:53

1 Answers1

1

If you want a validation before the user submit, you can try something like this :

<%= f.submit :onclick => "show_custom_confirm()" %>

<% javascript_tag do %>
  function show_custom_confirm() {
    if ('#my_field').val() == '')
      return #{confirm_javascript_function("You'll submit with an empty field. Are you sure?")};
  }
<% end %>
pierallard
  • 3,326
  • 3
  • 21
  • 48