Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda