Rails UJS Reenable Submit Button After Validation

289 views Asked by At

Rails will automatically disable submit buttons when submitting a form. The issue comes when you need to reenable it after performing a validation.

1

There are 1 answers

0
Tony Petruzzi On

Below is a quick fix to reenable the submit button. NOTE: that you have to use a setTimeout as to prevent a race condition.

setTimeout(function(){
  document.querySelectorAll('[data-disable-with]').forEach(function(element){
    $.rails.enableElement(element);
  });
});