.product_stock_form.field
  %hr
  %table{:style => "width:100%;"}
    %tr
      %td
        =# form.input :p_product_id, :label => "Produit :", :collection => PProduct.all, :as => :select, :include_blank => false , :input_html =>{:readonly => (true if form.object.lock == true)}
        
        
        
        
        =hidden_field_tag :last_p_product_id, form.object.p_product_id
        %label Produit :
        %input.p_product_autocomplete_input.form-control{:type => "text", :value => ("#{form.object.p_product.code} #{form.object.p_product.name}" if form.object.p_product)}
       
      
        = form.text_field :p_product_id, :class => "p_product_id"
        
        :javascript
          $( function() {
              
              $('.p_product_autocomplete_input').autocomplete({
                 source: function( request, response ) {
                         $.ajax( {
                           url: "/admin/p_products/autocomplete.json",
                           dataType: "json",
                           data: {
                             search: request.term
                           },
                           success: function(data){
                           
                             arr = jQuery.map( data, function( item ) {
                                                 return {
                                                     label: item.code+" "+item.name,
                                                     value: item.code+" "+item.name,
                                                     id: item.id
                                                 }
                             });
                             
                             response(arr)
                   
                           }
                           
                         } );
                       },
                 minLength: 2,
                 select: function( event, ui ) {
                   alert(ui.item.id);
                   $(this).next(".p_product_id").val(ui.item.id)
                   //$(this).val(ui.item.label)
                   return false
                 }
              });
              
              
              
            } );
            
          
    
      
      
        
        
        
      %td
        -if form.object.lock == true
          Externe :
          =form.object.externe ? "oui" : "non"
        -else
          = form.input :externe, :label => "Stock externe ?"
  

    %tr
    
      %td
        = form.input :qte, :label => "Quantité annoncée:", :input_html =>{:readonly => (true if form.object.lock == true)}, :inline => true
      %td  
        = form.input :price, :label => "Prix annoncé :" , :input_html =>{:readonly => (true if form.object.lock == true)}
      -if false
        %td= form.input :ok_at, :label => "Date de livraison :", :input_html =>{:readonly => (true if form.object.lock == true)}, :as => :date_select
     
    -if false 
      %tr
      
        %td= form.input :ok_qte, :label => "Quantité livrée :" , :input_html =>{:readonly => (true if form.object.lock == true)}
        %td= form.input :ok_price, :label => "Prix livré :" , :input_html =>{:readonly => (true if form.object.lock == true)}
    
        %td
          -if form.object.lock == true
            Livrée :
            =form.object.ok ? "oui" : "non"
          -else
            = form.input :ok, :label => "Livrée ?", :input_html =>{:readonly => (true if form.object.lock == true)}
  -if form.object.lock != true  
    =link_to_remove_fields ic(:"trash-o"), form