The form is a modal form, which looks like this:
<div class="modal-dialog modal-sm"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" align="center">Select tags</h4> </div> <div class="modal-body"> <% select Content.select_tags do |tag| %> <li> <%= form_for tag, remote: true do |f| %> <%= f.check_box "selected" %> <%= tag.tagname %> <% end %> </li> <% end %> </div> <div class="modal-footer"> <div class="row text-center"> <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary btn-sm submitme">Select</button> </div> </div> </div> </div>
The submit button is actually outside of the main form, so it doesn't do anything if it is used as is. However, it is possible to call it using jQuery:
$('.submitme').on('click',function(){
var valuesToSubmit = $('.edit_tag').serialize();
$.ajax({
url: $('.edit_tag').attr('action'),
data: valuesToSubmit
}).success(function(data){
$('.edit_tag').trigger('submit.rails');
});
return false;
)};
submitme is the button to be clicked, and edit_tag is the name of the form automatically generated by Rails. The serialize() method creates a text string in a standard URL-encoded notation and serializes controls within the form. attr('action') allows to select an appropriate url to which to send data.Most interestingly, I've stumbled across an interesting way to actually trigger the event:
$('yourform').trigger('submit.rails'). Thanks to Stack Overflow wisdom.
No comments :
Post a Comment