=semantic_form_for [:admin, @p_payment], :remote => true do |f| -@p_customer = @p_payment.p_customer if @p_payment.p_customer .content =f.inputs do =hidden_field_tag :last_p_customer_id, @p_payment.p_customer_id %label Client : %input.p_customer_autocomplete_input.form-control{:type => "text", :value => ("#{f.object.p_customer.show_name}" if f.object.p_customer)} = f.hidden_field :p_customer_id, :class => "p_customer_id" :javascript $( function() { $('.p_customer_autocomplete_input').autocomplete({ source: function( request, response ) { $.ajax( { url: "/admin/p_customers/autocomplete.json", dataType: "json", data: { search: request.term, }, success: function(data){ arr = jQuery.map( data, function( item ) { return { label: item.show_name, value: item.show_name, id: item.id } }); response(arr) } } ); }, minLength: 2, select: function( event, ui ) { $(this).next(".p_customer_id").val(ui.item.id) var change_address = false; if (parseInt($("#last_p_customer_id").val()) != parseInt(ui.item.id)){ change_address = true; } $.ajax({ url:"/admin/p_customers/"+ui.item.id+"/autocomplete_apercu.js", type : "GET", data : { change_address : change_address} }); $("#last_p_customer_id").val(ui.item.id); //return false } }); } ); %br =render :partial => "admin/p_payments/essentials_form", :locals => {:form => f} =f.inputs do %hr .p_payment_documents_form =f.semantic_fields_for :p_payment_documents do |form| =render :partial => "admin/p_payment_documents/form", :locals => {:form => form} %p= link_to_add_fields "Ajouter une ligne", f, :p_payment_documents = f.input :i_archive, :label => "Indiquer le lettrage comme effectué ? (forcer, même si aucun lettrage fait)" -not_comptant_ids = PPaymentType.where(:comptant => false).ids :javascript not_comptant_ids = #{not_comptant_ids}; :coffeescript $('.payment_type_id_select').change -> val = $(this).val() if $.inArray(parseInt(val), not_comptant_ids) isnt -1 $(this).closest(".field").find(".not_comptant").show() else $(this).closest(".field").find(".not_comptant").hide() .actions=f.submit "sauvegarder", :class => "btn btn-primary"