1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

railsでsubmitをキャンセルする

Posted at

参考:https://www.sejuku.net/blog/28720#submit

「false」を渡してあげるだけです。


<%= form_for @wifi_agency, html: {class: 'form'}  do |f| %>
  <%= f.text_field :name, :class=>"form-control"%>
  <%= f.submit "保存", class: "btn btn-success", :onclick => "return check_name()"%>
<% end %>

<script>
  function check_name() {
    if (!$("#name").value){
      //空だったらfalseを返してsubmitをキャンセル
      return false;
    } 
  }
</script>
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?