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?
$(document).on('ready turbolinks:load', function() {});instead$(document).ready(function() {});