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

182
Visualizações
disable submit button until all form inputs have a value in Rails

I would like to disable the form submit button until all inputs have a value in them. My view has these inputs:

  <%= form_for @item, html: { enctype: "multipart/form-data", id: "upload-data" } do |f| %>
   <%= f.text_field :name %>
  <% end %>

I then run this validate() function with every keyup event:

$(document).ready(function() {
  validate();
  $('input').on('keyup', validate);
});

function validate() {
  var input = $('input');
  var isValid = false;
  $.each(input, function(k, v) {
    if (v.type != "submit") {
      isValid = (k == 0) ?
        v.value ? true : false : isValid && v.value ? true : false;
    }
    if (isValid) {
      $("input[type=submit]").prop("disabled", false);
    } else {
      $("input[type=submit]").prop("disabled", true);
    }
  });
}

Though the same code works here it does not work in my Rails view. It stays disabled. What am I overlooking?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

maybe because turbolinks, in rails you can't just copy paste the javascript you need to adapt it into turbolinks script and syntax

you could try to change your script from

$(document).ready(function() {

});

into

$(document).on('ready turbolinks:load', function() {

})
about 4 years ago · Juan Pablo Isaza Relatório
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