Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

131
Vistas
Hide remove link for single input field

In my rails app, I have used nested form fields gem for adding and removing contacts fields in my Employee creation form. HTML for contact fields looks like this:

<h3 class= "fw-bold mt-2">Contacts:</h3>
<div class="nested_form_field">
  <%= f.nested_fields_for :contacts do |contact| %>
    <div class="fields-row">
      <%= contact.label :number, class: "m-1"%>
      <%= contact.text_field :contact_no, placeholder: "Enter Contact", class: "m-1" %>
      <%= contact.remove_nested_fields_link 'Remove', data: { confirm: 'Are you sure?' }, class: "link-danger remove_fields" %>
    </div>
  <% end %>
</div>
<%= f.add_nested_fields_link :contacts, 'Add Contact', class: 'btn btn-secondary btn-sm mt-1' %>

Here, I want to make changes to the view such that when the input field for contact number is only one, the link to remove contact should hide. For that, I have added this code to application.js:

$(document).ready(function (){  
  if ($(".fields-row").length == 1) {
    $(".remove_fields").hide();
  }
})

So when the page loads, there is no link to remove, but after adding multiple fields, each field gets a link to remove except first one. I want to change the js such that even first contact can be removed and when there is only one contact available, the link should hide. Please help.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda