borod108
borod108

Reputation: 796

rails form validation empty filed

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)

Upvotes: 0

Views: 105

Answers (1)

pierallard
pierallard

Reputation: 3371

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 %>

Upvotes: 1

Related Questions