私はjQueryのtokeninput入力に問題があるため、複数の入力を生成し、これはレールのコードで私のルビー:jQueryのtokeninputは、1つの入力
<% @free_preferences.each do |fp| %>
<% eventCriteria = EventCriteria.find_by_id(fp.event_criteria_id)%>
<% if !eventCriteria.is_exclusive? %>
<% form_for fp do |f| %>
<%= f.label :tag_tokens1, eventCriteria.name %>
<%= f.text_field :tag_tokens1, "data-pre" => fp.tags.map(&:attributes).to_json %>
<%= f.submit "Save preference", :disable_with => 'Saving preference...' %>
<% end %>
<% else %>
<% form_for fp do |f| %>
<%= f.label :tag_tokens2, eventCriteria.name %>
<%= f.text_field :tag_tokens2, "data-pre" => fp.tags.map(&:attributes).to_json %>
<%= f.submit "Save preference", :disable_with => 'Saving preference...' %>
<% end %>
<% end %>
はそして、この生成されたHTMLソースコード:
<form accept-charset="UTF-8" action="/subscription_preferences/128" class="edit_subscription_preference" id="edit_subscription_preference_128" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="_method" type="hidden" value="put" /><input name="authenticity_token" type="hidden" value="bYJedYxgjjA+C+CWUkZpXH3mxNxOf8XPQgwp5/DEUp8=" /></div>
<label for="subscription_preference_tag_tokens1">Explicit include</label>
<input data-pre="[{"updated_at":"2012-03-20T08:48:53Z","name":"Windows xp","id":70,"created_at":"2012-03-20T08:48:53Z"}]" id="subscription_preference_tag_tokens1" name="subscription_preference[tag_tokens1]" size="30" type="text" />
<input data-disable-with="Saving preference..." id="subscription_preference_submit" name="commit" type="submit" value="Save preference" />
<form accept-charset="UTF-8" action="/subscription_preferences/129" class="edit_subscription_preference" id="edit_subscription_preference_129" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="_method" type="hidden" value="put" /><input name="authenticity_token" type="hidden" value="bYJedYxgjjA+C+CWUkZpXH3mxNxOf8XPQgwp5/DEUp8=" /></div>
<label for="subscription_preference_tag_tokens2">Explicit exclude</label>
<input data-pre="[]" id="subscription_preference_tag_tokens2" name="subscription_preference[tag_tokens2]" size="30" type="text" />
<input data-disable-with="Saving preference..." id="subscription_preference_submit" name="commit" type="submit" value="Save preference" />
それは良いようだが、問題は、私は放火犯をチェックすると、これはコードで、各subscription_preference_tag_tokensX入力するための4つのjQuery tokeninputsが作成されることです。
<form accept-charset="UTF-8" action="/subscription_preferences/128" class="edit_subscription_preference" id="edit_subscription_preference_128" method="post">
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; display: inline; ">
<label for="subscription_preference_tag_tokens1">Explicit include</label>
<ul class="token-input-list-facebook">
<ul class="token-input-list-facebook">
<ul class="token-input-list-facebook">
<ul class="token-input-list-facebook">
<input data-pre="[{"updated_at":"2012-03-20T08:48:53Z","name":"Windows xp","id":70,"created_at":"2012-03-20T08:48:53Z"},{"updated_at":"2012-03-13T10:01:10Z","name":"something","id":59,"created_at":"2012-03-13T10:01:10Z"}]" id="subscription_preference_tag_tokens1" name="subscription_preference[tag_tokens1]" size="30" type="text" style="display: none; "/>
<input data-disable-with="Saving preference..." id="subscription_preference_submit" name="commit" type="submit" value="Save preference"/>
</form>
<form accept-charset="UTF-8" action="/subscription_preferences/129" class="edit_subscription_preference" id="edit_subscription_preference_129" method="post">
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; display: inline; ">
<label for="subscription_preference_tag_tokens2">Explicit exclude</label>
<ul class="token-input-list-facebook">
<ul class="token-input-list-facebook">
<ul class="token-input-list-facebook">
<ul class="token-input-list-facebook">
<input data-pre="[]" id="subscription_preference_tag_tokens2" name="subscription_preference[tag_tokens2]" size="30" type="text" style="display: none; "/>
<input data-disable-with="Saving preference..." id="subscription_preference_submit" name="commit" type="submit" value="Save preference"/>
</form>
IRは4「を作成し、なぜ私にはわかりませんtoken-各「subscription_preference_tag_tokensX」に対して「input-list-facebook」を追加する。これは、問題の写真です:
EDIT 1:
これは私のjQueryのコードです:
$(function() {
$('#subscription_preference_tag_tokens1').tokenInput('/tags.json', {
crossDomain: false,
preventDuplicates: true,
prePopulate: $('#subscription_preference_tag_tokens1').data('pre'),
theme: 'facebook',
});
$('#subscription_preference_tag_tokens2').tokenInput('/tags.json', {
crossDomain: false,
preventDuplicates: true,
prePopulate: $('#subscription_preference_tag_tokens2').data('pre'),
theme: 'facebook',
});
});
JavaScriptコードを投稿できますか? – moritz
こんにちはmosch、私は私の質問を編集した、あなたはポストの最後にjavascriptコードを見つけることができます。 – TomasMax