0
クローンされた のものが機能していないため、新しい行をクローンしたときにSelect2が機能しなくなりました。 "ドロップダウンメニューの操作 最初の行(デフォルトのもの)のみ"ドロップダウンメニュー。ここに私のコードは次のとおりです。select2は複製された行に対して機能しません。なぜですか?
**= f.inputs 'Items not in inventory' do
%table
%thead
%td{style: 'width: 20%; padding-left: 20px;'}
%b Select Product
%td{style: 'max-width: 70px;'}
%b Repossessed Inventory (Serial/Amount)
%tbody{id: 'tableToModify'}
%tr{id: 'rowToClone'}
= semantic_fields_for :other_stuff do |os|
%td{style: 'padding-left: 20px;'}
= os.input :product_id, as: :select, label: false, collection: Product.all.order(:name).pluck(:name, :id), input_html: {class: 'select2'}
%td
= os.input :repossessed, label: false, input_html: { style: 'width: 100px;' }
%td
= link_to "x", "javascript:if ($('#tableToModify tr').length > 1) {document.getElementById('tableToModify').deleteRow($('#tableToModify tr').length - 1);}"
= link_to 'Add item', 'javascript:cloneRow()'
= f.input :rest_is_lost, as: :boolean, label: 'Mark unrepossessed items as lost', input_html: { checked: 'checked' }
= f.actions do
= f.action :submit, label: 'Create Repossession Case'
= f.action :cancel, label: 'Cancel', button_html: { href: url_for(action: :index) }, wrapper_html: { class: :cancel }
:javascript
function cloneRow(){
var row = document.getElementById("rowToClone");
var table = document.getElementById("tableToModify");
var clone = row.cloneNode(true);
var numberOfRows = document.getElementById("tableToModify").rows.length;
clone.id = numberOfRows + 1;
table.appendChild(clone);
}**
は先端のためにあなたをとても感謝が、これはあまりにも機能していません入力内の要素を取得し、select2でバインドされていますが、何度も失敗します。どうしてか分かりません!!! –
それは私にこのエラーを与えます:clone.getElementByIdは関数ではありません –
'console.log(clone)'を使って 'clone'を確認します。 –