Skip to content

Commit 78b84e2

Browse files
committed
fix(frontend): reabilita botões de submit após navegação e validação HTML5
- Implementa handler global em base.html que reabilita botões de submit em todos os formulários ao retornar via back/forward cache (bfcache), ao ocorrer falha de validação HTML5 ou quando o submit é barrado. - Evita que o botão permaneça desabilitado, melhorando a usabilidade e compatibilidade cross-browser. - Permite exceções via atributo data-keep-disabled para casos especiais. Para exceções, marcar o botão com o atributo data-keep-disabled. closes #3350, closes #2440
1 parent 78110b8 commit 78b84e2

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

sapl/templates/base.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,47 @@ <h1 class="page-header">
270270

271271
{% block extra_js %}{% endblock extra_js %}
272272

273+
<script>
274+
(function(){
275+
// Reabilita botões de submit, exceto os marcados explicitamente
276+
// com data-keep-disabled (casos especiais que devem permanecer desabilitados).
277+
function enableFormSubmits(scope){
278+
var root = scope || document;
279+
var btns = root.querySelectorAll('button[type="submit"]:not([data-keep-disabled]), input[type="submit"]:not([data-keep-disabled])');
280+
btns.forEach(function(b){
281+
try { b.disabled = false; b.removeAttribute('aria-disabled'); } catch(_){}
282+
});
283+
}
284+
285+
// Reabilita submits ao retornar via back/forward cache (Firefox)
286+
window.addEventListener('pageshow', function(e){
287+
try {
288+
var nav = (performance && performance.getEntriesByType) ? performance.getEntriesByType('navigation')[0] : null;
289+
var backForward = nav && nav.type === 'back_forward';
290+
if (e.persisted || backForward) {
291+
enableFormSubmits();
292+
}
293+
} catch(_) { enableFormSubmits(); }
294+
});
295+
296+
// Em falha de validação, garante reabilitação dos botões do formulário
297+
document.addEventListener('invalid', function(ev){
298+
if (ev && ev.target && ev.target.form) {
299+
enableFormSubmits(ev.target.form);
300+
}
301+
}, true);
302+
303+
// Se a submissão não é válida, evita desabilitar permanente
304+
document.addEventListener('submit', function(ev){
305+
var form = ev && ev.target;
306+
if (form && typeof form.checkValidity === 'function' && !form.checkValidity()){
307+
try { ev.preventDefault(); } catch(_){}
308+
enableFormSubmits(form);
309+
}
310+
}, true);
311+
})();
312+
</script>
313+
273314
<script type="text/javascript" >
274315
function inIframe () {
275316
try {

0 commit comments

Comments
 (0)