%tr.m_odr_file_roulage_form.field
  %td.td_roulage_date_input= form.input :date, :label => "date :" , :as => :date, :input_html => {:class => "roulage_date_input"}
  
  -if form.object.date?
    %td= form.input :m_event_id, :label => "Journée de roulage :", :as => :date, :collection => MEvent.order("start_at").where("start_at <= ? and end_at >= ?", form.object.date, form.object.date).all, :member_label => :member_label, :as => :select, :input_html => {:class => "select_date_input"}
    
  -else
    %td= form.input :m_event_id, :label => "Journée de roulage :", :as => :date, :collection => [], :member_label => :member_label, :as => :select, :input_html => {:class => "select_date_input"}
    =#%td= form.input :m_event_id, :label => "Journée de roulage :", :as => :date, :collection => MEvent.all, :member_label => :member_label, :as => :select
  
            
  %td.actions=link_to_remove_fields ic(:"trash-o"), form
  
  
  
:coffeescript
  
  $("body").on "change", ".td_roulage_date_input input", ->
    obj = $(this)
    $.getJSON "/admin/m_events/autocomplete.json?date="+$(this).val(), (data) ->
      obj.closest(".field").find(".select_date_input").html("")
      $.each data, ->
        obj.closest(".field").find(".select_date_input").append '<option value="' + @id + '">' + @member_label + '</option>'
