Submit Select2 Form in Rails via Javascript with Acts

I have a tags list I'm showing on a page when the user visiting the page is the owner. I would like this individual to be able to adjust the tags to a photo directly on the page. As tags are added, it would update the Acts-as-taggable on field against the photo. I'm really close to having everything work correctly, the only thing I can not get successfully is the remote save of this data (it works when I add a submit button to the page and click this button.)

Gems: (I have manually added the script for Select2)

gem 'simple_form'
gem 'acts-as-taggable-on'

My form:

<%= simple_form_for [@mountain, @photo], remote: true do |f| %>
    <%= f.input :tag_list, label: false, :input_html => {class: 'select2-container select2-container-multi', style: 'width:100%'}  %>
    <%= f.submit "Update tags" %>
<% end %>

My desire is to remove the submit button within this form.

Here is the script which renders the form as a Select2 form with tags:

<script type="text/javascript">
    $("#photo_tag_list").select2({tags:[], width: 'resolve', placeholder: "Add photo tags" });
    $("#photo_tag_list").on("change", function() { 
        $("#photo_tag_list_val").html($("#photo_tag_list").val());
    });

    $("#photo_tag_list").select2("container").find("ul.select2-choices").sortable({
    containment: 'parent',
    start: function() { $("#photo_tag_list").select2("onSortStart"); },
    update: function() { $("#photo_tag_list").select2("onSortEnd"); }
    });
</script>

I have tried the following with help of the chrome console to try to submit the form: 1) add a value to the tags list, 2) go to console and run $("#photo_tag_list").submit();. I get the following message, where the value I have added is not within the value="".

<input class=​"string optional select2-container select2-container-multi" id=​"photo_tag_list" name=​"photo[tag_list]​" size=​"50" style=​"width:​ 100%;​ display:​ none;​" type=​"text" value=​"description_blank, pack, champions">​

Thanks in advance for the help! Please let me know if it is helpful to see some more of the code.

链接地址: http://www.djcxy.com/p/36022.html

上一篇: 红宝石在轨道上

下一篇: 使用Acts通过Javascript提交Select2 Form in Rails