I have a Rails form, to which I have attached a submit handler which has a try / catch block and in the catch block, I display error message to the user and try to re-enable the submit button.
The button for some reason does not get re-enabled.
If I execute the same code in browser console later, the button gets re-enabled.
below is the relevant part of the code
function displayError(action,err){
jQuery('input[name=commit]').removeAttr('disabled');
};
form.addEventListener('submit', (event) => {
try {
} catch(e) {
displayError('submit', e);
}
});
Any help on this will be really great, Thanks.
*** Update 1
if i console.log(jQuery('input[name=commit]')); I see this
YOu can use JQuery to enable and disable buttons in a UI. Assume the id of the button is
id="singlebutton"
Using JQuery, you can disable this button via this code:
$('#singlebutton').prop("disabled", true);
This disables the button.
Likewise to enable it, use:
$('#singlebutton').prop("disabled", false);