Onclick respect required field

0

I created an animation that appears on the screen and blocks the fields entered by the user while the request is processed, directly in submit , as below:

onclick="javascript:document.getElementById('blanket').style.display = 'block';document.getElementById('aguarde').style.display = 'block'; block();"

The image below appears:

It happens that if the user does not fill in some information, the form is not sent and the warning appears due to the required , but the animation is executed anyway, and to return the page only updating the it.

Is there any way to onClick wait for validation of required fields before running this animation?

    
asked by anonymous 03.02.2017 / 13:57

1 answer

1

In this case the onclick will be executed anyway. In order for this block validation to be enabled only if the criteria are met, put the onsubmit event in and drop onclick . It can be something like:

document.getElementById('meu_form').addEventListener("submit", function(){
    document.getElementById('blanket').style.display = 'block';
    document.getElementById('aguarde').style.display = 'block'; 
    block();
});
    
03.02.2017 / 14:10