You are viewing limited content. For full access, please sign in.

Question

Question

how can i find out that submit action returns false or true

asked on March 11, 2015

Hello,

 

After hitting the submit button , If there is any  error , LF will navigate user to the first error and the page can't be submitted . 

 

My questions is how can i find out that submit action returns false or true ?

because I need to show a message to the users on the page  if the page is not submitted successfully (due to errors ) after hitting the submit button .

 

Thanks.

 

 

1 0

Replies

replied on March 12, 2015

When click the submit button, it will do validation for the fields(check whether the required fields are filled and whether the format for the fields are valid), if the field can't pass the validation, then Forms will add a "ws-invalid" class to that field, you can check after click submit button whether there is element with "ws-invalid" on the form to detect whether there is error when submitting.

Can you share the use case with us why you need to show a message on the page? By default Forms will highlight the field and show error message below the field when field can't pass validation, this can't meet your requirement?

0 0
replied on March 25, 2015

Hello,

 

I am creating some fields (HTML Elements )  dynamically in the page  that need to be validated  , .I know  if the field can't pass the validation,  A "ws-invalid" should be added  to the parent DIV and also   a  'user-error'  class should be  added to that filed .

 So , I need to modify the java script code when the page is submitted . Here is my code :

    $('#form1').on('submit', function (event) {

        HoursDayValidation();
        if ($('li[attr=PracticeLocationLI_Time] .user-error').length > 0 && $('.ws-invalid').length == 0)                return false;  *(A)

    })

But when I return "False"(A) , LF keeps submitting the page and does prevent form from being submitted .

 

And also I tried to use event.preventDefault() instead of return "False" but still the form is being submitted .

How can i prevent form from being submitted ?

 

Regards,

Reza.

0 0
replied on March 27, 2015 Show version history

The following code works for me in preventing form from being submitted:

$(document).ready(function() {
    $("#form1").on( "submit", function( event ) {
      event.preventDefault();
    });
});

Did you add document ready in your code? If the above code doesn't work for you, can you share us the whole code?

0 0
replied on September 4, 2020

Hi, 

 

I did it with the following class:

var RequireError = $('.parsley-required').val();  
if (RequireError == undefined) 
 {
   alert('Success')								
 }
else
 {
   alert('Empty Field Error')
 }

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.