[英]Trigger jQuery with form_for in Ruby on Rails
I'm new in Ruby on Rails and I'm trying to make to form_for
trigger a jQuery function. 我是Ruby on Rails的新手,我正在尝试使form_for
触发jQuery函数。
My code for the form is the next: 我的表单代码如下:
<%= form_for @company, :url => create_paying_registration_path(:industry => apt(@plan.industry, :industries), :plan => @plan.name),
:html => {:id => "card-form"} do |f| %>
<%= render 'form_carrier', :company => @company, :plan => @plan, :f => f %>
<% end %>
And jQuery: 和jQuery:
jQuery ($) ->
$("#card-form").submit ->
$form = $(this)
$form.find("button").prop "disabled", true
Conekta.token.create tokenParams, conektaSuccessResponseHandler, conektaErrorResponseHandler
false
return
The form doesn't trigger the jQuery function but if I use a form_tag
, it triggers the jQuery function: 表单不会触发jQuery函数,但是如果我使用form_tag
,它将触发jQuery函数:
<%= form_tag('/checkouts/charge', id: 'card-form') do %>
My question is, what am I doing wrong with form_for
? 我的问题是, form_for
在做什么? I need to trigger the jQuery and then redirect to the path from form. 我需要触发jQuery,然后从表单重定向到路径。
Thanks in advance. 提前致谢。
Add onSubmit to form_for 将onSubmit添加到form_for
form_for @paintings, :url => "/paintings/handlelike", :method => "post", :remote => true, :html => {:id => "submit_form_id",:onsubmit => "yourFunction();", :name => 'form'} do |f|
And in your js: 在你的js中:
yourFunction() {
$form = ...
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.