Rails - passing an id for a checkbox -
so have button:
<button class="btn btn-success" id="btn_renew" onclick="lo_items_navigate('<%= renew_account_lo_item_path(@account, :id => 0) %>');"><i class="fa fa-refresh"></i> <%= t('toolbar.renew_label') %></button>
i have checkbox each row in table. user can choose 1 checkbox (i have use checkboxes).
if user checks checkbox, button becomes visible , can click it. how , pass id item in table rails url?
for part:
onclick="loa_items_navigate('<%= renew_account_loa_item_path(@account, :id => 0) %>')
my id listed in checkboxes this:
<input class="select" type="checkbox" data_value="<%= lo_item.id %>" />
how populate id>? ideas?
i add data-url
attribute, , write simple js plugin, listen click
event, , make ajax request url data-url
attribute
if have data-id
attribute (should dash actually, not underscore), can this:
<input class="select" type="checkbox" data-id="<%= lo_item.id %>" /> <button data-url="/url/:id" data-trigger="navigate-to-item" > $(document).ready(function() { $('button[data-trigger*="navigate-to-item"]').click(function(event) { id = $('input.select:checked').data('id'); url = $(event.target).data('url').replace(':id', id); // , here can url }); })
Comments
Post a Comment