Rails remote form and select on change not working

前端 未结 3 777
迷失自我
迷失自我 2021-01-18 11:55

I was trying to follow: Rails: submit (via AJAX) when drop-down option clicked

However none of these options appear to work (onsubmit, submit)

This is what I

3条回答
  •  一向
    一向 (楼主)
    2021-01-18 12:23

    I ended up making a event bind as per Marc's suggestion

    = simple_form_for task, :remote => true, :format => :js, :html => {:id => "task_#{task.id}_status"} do |f|
                = f.association :status, :label => false, :include_blank => false, :input_html => {:id => "task_#{task.id}_status_select" }
    
    :javascript
            jQuery(function($) {
              $(document).ready(function() {
                $("#task_#{task.id}_status_select").bind("change", function() {
                  $.ajax({
                    type: "PUT",
                    url: '#{project_story_type_story_task_path(@project, @story_type, @story, task)}',
                    data: 'task[status_id]=' + $('#task_#{task.id}_status_select').val(),
                    complete: function() {
                      $('#task_#{task.id}_status').prepend("SAVED");
                      $('#task_#{task.id}_success').delay(500).fadeOut();
    
                    }
                  });
    

提交回复
热议问题