带有自动完成功能和茧形宝石嵌套资源的Rails物化-无礼形式 [英] Rails materialize-sass form with autocomplete and cocoon gem nested resource

查看:76
本文介绍了带有自动完成功能和茧形宝石嵌套资源的Rails物化-无礼形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单上使用 materialize-sass 宝石.使用自动完成功能获取供应商名称.表单上的其他字段是作为嵌套资源的项目名称和数量.为此,我正在使用 gem

I am using materialize-sass gem on a form. Using autocomplete feature to get Vendor names. other fields on the form are item names and quantity which are a nested resource. For this I am using cocoon gem

由于某种原因,页面第一次加载时,一切似乎都正常.但是添加更多字段似乎没有用.我尝试使用下拉选择,但未显示项目列表.我用另一个自动完成功能替换了它,并且主字段确实显示了,但是自动完成功能不起作用.知道有什么问题吗?

For some reason the very first time the page loads, all seems to work fine. But adding more fields does not seem to be working. I tried using drop down select and that does not show the list of items. I replaced it with another autocomplete and the main field does show however the auto complete feature does not work. Any idea what may be wrong?

请在下面查看我的代码.

Please see my code below.

purchase_orders _forms.html.erb

purchase_orders _forms.html.erb

<div class="col s12">
	<%= simple_form_for(@purchase_order) do |f| %>
	<%= f.error_notification %>
	<div class="row">
		<div class="col s6">
			<%= f.input :vendor_name, input_html: { class: 'vendor_name autocomplete' } %>
		</div>
	</div>
	<section class="show-section">
		<div class="row">
			<div class="col l12"><h4>Item List</h4></div>
			<div class="col s12">
				<%= f.simple_fields_for :purchase_order_details do |purchase_order_detail| %>
				<%= render 'purchase_order_detail_fields', :f => purchase_order_detail %>
				<div class="links">
					<%= link_to_add_association 'Add More', f, :purchase_order_details %>
				</div>
				<% end %>
			</div>
		</div>
	</section>
	<%= f.button :submit %>
	<% end %>
</div>

_purchase_order_detail_fields.html.erb

_purchase_order_detail_fields.html.erb

<div class="nested-fields">
	<div class="row">
		<div class="col l6">
			<%#= f.input(:item_id, collection: Ingredient.is_active, label_method: :title, value_method: :id) %>
			<%= f.input :item_name, input_html: { class: 'item_name autocomplete' } %>
		</div>
		<div class="col l5">
			<%= f.input :item_quantity %>
		</div>
		<div class="col l1">
			<%= link_to_remove_association "delete", f, :class => "material-icons teal-text text-lighten-1" %>
		</div>
		<%#= f.hidden_field :item_type , :value=> params[:category_id] %>
	</div>
</div>

推荐答案

这是我以前用来填充自动拼版的咖啡脚本

This is the coffee script I used to be able to populate the autocompelte

$.ajax
  url: '/packing_materials/by_name.json'
  dataType: 'json'
  success: (my_res) ->
    $ ->
      $('input.packing_material_name.autocomplete').autocomplete data: my_res

$(document).on 'cocoon:before-insert', ->
  $.ajax
    url: '/packing_materials/by_name.json'
    dataType: 'json'
    success: (my_res) ->
      $ ->
        $('input.packing_material_name.autocomplete').autocomplete data: my_res

这篇关于带有自动完成功能和茧形宝石嵌套资源的Rails物化-无礼形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆