2017-11-03 4 views
0

このアイテムのインデックスはページに表示されています。このページでは、各アイテムにリンクがあり、一意のモーダルを開くことができます。このモーダルで私は:ユーザ名テキストフィールドとそれに対応するajaxコールを持っていますので、@usernameと入力すると、あなたの友人のユーザ名がポップアップします。とにかく、これは最初のitem-link-modalコンボだけで動作し、後続のitem/link/modal combosは機能しません。私はこだわっているのはここだ、任意のヘルプは大歓迎:ajaxは後続のモーダルフォームで起動しません

モーダル部分:

<div class="modal fade" id="pirateinvite-<%= x.id %>" tabindex="-1" 
role="dialog" aria-labelledby="pirateinviteLabel" aria-hidden="true"> 
<div class="modal-dialog" role="document"> 
<div class="modal-content"> 
    <div class="modal-header"> 
    <h5 class="modal-title" id="pirateinviteLabel">Invite a friend</h5> 
    <button type="button" class="close" data-dismiss="modal" aria-label="Close"> 
     <span aria-hidden="true">&times;</span> 
    </button> 
    </div> 
    <div class="modal-body"> 
    blah blah 

    <%= form_for @invitations, :url => invitations_path, :method => 'create', remote: true do |b| %> 

    <div class="form-group"><center> 
     <b><%= b.label :username, 'Invite by username:' %></b></center> 
     <%= b.text_area :username, rows: 1, class: 'form-control', required: true, placeholder: "@user1 @user2" %> 
     <%= b.hidden_field :event_id, :value => x.id %> 
    </div> 
    <div class="text-center"> 
    <%= b.submit 'Send an Invite!', class: 'btn btn-primary btn-sm align-self-center' %> 
    <% end %></div> 

    </div> 
</div> 

invitations.coffeeモーダルで各テキストエリアIDを作るために必要な

class @Invitation 

@add_atwho = -> 
$('#invitation_username').atwho 
    at: '@' 
    displayTpl:"<li class='mention-item' data-value='(${image},${name})'><img src=${image}>@${name}</li>", 
    callbacks: remoteFilter: (query, callback) -> 
    if (query.length < 1) 
     return false 
    else 
     $.getJSON '/mentionsy', { q: query }, (data) -> 
     callback data 

jQuery -> 
Invitation.add_atwho() 

答えて

0

ユニークに変更して<%= b.text_area :username, id: "invitation_username_#{+ x.id}", rows: 1, role: "textarea", class: 'form-control', required: true, placeholder: "@user1 @user2" %>

そのようなユニークなテキスト領域をすべて聞くためにリスナーを変更する必要があります:$('textarea[id^=invitation_username_]').atwho

関連する問題