Uncaught TypeError: $(...)[0].reset is not a function

Uncaught TypeError: $(...)[0].reset is not a function

目标

表单提交成功后,我想将表单重置为空。

问题

提交表单后,我在控制台中收到以下错误消息:Uncaught TypeError: $(...)[0].reset is not a function

当我在重置前 console.log 我的内容时,我得到表格:<div id=new-store-form>..</div>

到目前为止我检查了什么

代码 views/stores/index.html.erb

<div class="show-panel-form"></div>
  <%= render "partials/show_panel_stores_overview"%>
</div>

views/partials/show_panel_stores_overview.html.erb

<%= link_to 'New store', new_store_path, remote: true %>

views/stores/new.js.erb

var form = $("<%= j(render 'form') %>");
var wrapper = $('<div>').attr('id', 'new-store-form').append(form);
$('.show-panel-form').html(wrapper);

views/stores/_form

<%= simple_form_for (Store.new) do |f|%>
<%= f.input :name %>
<%= f.button :submit%>

views/stores.创建.js.erb

var form = $("<%= j(render 'form') %>");
var wrapper = $('<div>').attr('id', 'new-store-form').append(form);
$('.show-panel-form').html(wrapper);
console.log($("#new-store-form")[0])
$("#new-store-form")[0].reset(); // doesn't work

店长

def new
    @store = current_user.store.build
    @store.age_tables.build
    respond_to do |format|
      format.html { redirect_to root_url, alert: 'Page not accessible' }
      format.js
    end
    authorize @store

  end

  def create
    @store = current_user.stores.create(store_params)
    authorize @store
    if @store.save
      respond_to do |format|
        format.js
      end
    else
      format.js
    end
  end

使用匹配表单的 selector,而不是包装器 $('#new-store-form form').reset()(注意额外的 "form" 到 select [=14] 中的实际表单标签=])