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

108
Vistas
Check Box adding 2 entries to Payload

I've the following in ruby file html.erb

<div class="hidden" id="contractor-group"> 
   <%= f.check_box :contractor, id: 'int_contractor_check'%>
   <label for="contractor">Internal Contractor</label>
</div>

function enableContractor() {
  var type = $('#company-type').val();
  if (type == 'INTERNAL') {
     $('#contractor-group').removeClass('hidden')
     $('#int_contractor_check').prop('checked', false);
  }
  else {
     $('#int_contractor_check').prop('checked', false);
     $('#contractor-group').addClass('hidden')
  }
}

A dropdown change to INTERNAL toggles the checkbox hidden/shown

id: "company-type",
onchange: "enableContractor()",

In the payload I get double contractor entries. Any ideas what I am doing wrong? enter image description here

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Nothing wrong here. For checkboxes Rails creates a hidden field with 0 value (you can check it in generated html). It's needed b/c checkbox value is send only when checkbox is checked. So, to avoid having nothing send, when it's not checked, we need this hidden input. When parsing it on the server, Rails will overwrite 0 with the latest value (1) See docs

about 4 years ago · Juan Pablo Isaza Denunciar

0

I stripped down the code to the following and it's working fine now. Using true and false was better to use on server side anyway. Not sure why the server wasn't using the value 1 ever,

Thanks @faron for the link, something I didn't know.

<div class="hidden" id="contractor-group">
   <%= f.check_box :contractor, { checked: false }, true, false %>
    <b> Internal Contractor </b>
</div>
about 4 years ago · Juan Pablo Isaza Denunciar
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