I've been trying the solutions outlined on this page: Disable commandButton after first click to prevent double submission
However, I am still creating multiple submissions. I am unsure if this is because I am first doing some js validation or if there is another reason? Is there a way to still do the validation and still have a hard stop after a single click? Below is the related code:
<apex:actionFunction name="saveNow" action="{!saveNowITellYou}"/>
<apex:commandButton id="hideSubmitButton" onclick="validateChecked()" value="Submit Form" action="{!saveNowITellYou}" styleClass="commandButton" style="
display: inline-block;
font-family: 'Futura WGU', Lato, arial, sans-serif;
text-transform: uppercase;
font-size: 12px;
font-weight: normal;
padding: 0 10px;
border-radius: 5px;
color: #002f51;
-webkit-tap-highlight-color: transparent;
cursor: pointer;
outline: none;
min-height: 28px;
line-height: 28px;
text-align: center;
background-image: none;
background-position: 0%;
margin: 0;"/>
<script>
//We use this to modify elements when we don't want those modifications to
//display on the PDF (Generated from the html)
var changeStyling = function(){
var submitButton = document.getElementById('addButtonColor').childNodes[1];
submitButton.style.backgroundColor = '#ffcc5b';
submitButton.style.borderColor = '#ffcc5b';
var formCheckbox = document.getElementById('formCheckbox');
formCheckbox.style.display = 'inline-block';
var fakeCheckbox = document.getElementById('fakeCheckbox');
fakeCheckbox.style.display = 'none';
var fakeCheckbox = document.getElementById('nameForPDF');
fakeCheckbox.style.display = 'none';
var formCheckbox = document.getElementById('formNameInput');
formCheckbox.style.display = 'inline-block';
}
var validateChecked = function() {
var errorTextDiv = document.getElementById('formErrorText');
var checkboxOutline = document.getElementById('checkboxOutline');
if(!formCheckbox.checked) {
errorTextDiv.style.display='block';
checkboxOutline.style.border='1px solid #be1e2d';
} else {
doSomeWork();
checkboxOutline.style.border='1px solid #fff';
//We no longer need the hideForPDF line but if it is removed
// the form doesn't submit for some reason.
document.getElementById('hideForPDF').style;
errorTextDiv.style.display='none';
}
}
function buttonsEnabled(enabled) {
// retrieve all of the buttons or links on the page
// with the css class of btn
var $buttons = jQuery('.btn');
if (enabled === false) {
// add the btnDisabled class to give it the look of being disabled
// add the disabled attribute to actually disable interactability
$buttons.toggleClass('btnDisabled', true).attr('disabled', 'disabled');
} else {
// remove the css class and the disabled attribute
$buttons.toggleClass('btnDisabled', false).attr('disabled', null);
}
}
function doSomeWork() {
// first, call the action function to post the form
saveNow();
// second, disable the buttons
buttonsEnabled(false);
// third, return false to prevent the click from
// posting the form a second time
return false;
}
changeStyling();
</script