Code Tips

So I've played a little with GPT5, Claude etc. to make some changes to make my app safer and reliable. the first thing that i found a big issue for me was the double click on button, some non tech users click twice on add account button or other forms which create errors and such, so you can add this code, it attached to any submit button and once clicked it display 🚫icon and prevent the next click, then after some time enable back by time (can change). Disclaimer! test it on you beta/test app before deploying, I've add it personally in Studio-Designer-Injection<BODY> injection

<script>
// Preventing Double Form Submission
function simpleDoubleSubmitPrevention() {
    document.addEventListener('click', function(e) {
        const target = e.target;
        
        // Check if this is a submit button (all possible cases)
        const isSubmitButton = (
            (target.tagName === 'BUTTON' && (target.type === 'submit' || !target.type)) ||
            (target.tagName === 'INPUT' && target.type === 'submit') ||
            target.name === 'do_submit' || // Specific match for your button
            target.classList.contains('bx-form-input-submit') // Match by class
        );
        
        if (isSubmitButton) {
            console.log('Submit button clicked:', target); // For debugging
            
            if (target.disabled) {
                e.preventDefault();
                return false;
            }
            
            // Save the original text
            const originalText = target.textContent || target.innerText || target.value;
            
            setTimeout(() => {
                target.disabled = true;
                target.style.opacity = '0.6'; // Add visual effect
                target.style.cursor = 'not-allowed';
                
                // Change the text
                if (target.textContent) {
                    target.textContent = 'Submitting...';
                } else if (target.value) {
                    target.value = 'Submitting...';
                }
                
                // Reset after 5 seconds
                setTimeout(() => {
                    target.disabled = false;
                    target.style.opacity = '';
                    target.style.cursor = '';
                    
                    if (target.textContent && target.textContent === 'Submitting...') {
                        target.textContent = originalText;
                    } else if (target.value && target.value === 'Submitting...') {
                        target.value = originalText;
                    }
                }, 5000);
            }, 10);
        }
    });
}


document.addEventListener('DOMContentLoaded', simpleDoubleSubmitPrevention);
</script>

 
  • 768
  • More
Replies (0)
Login or Join to comment.