is conditionally preventing the form submit event a race condition ?
I have the following submit code for my form:
- // Form submit code
- $('#gform_wrapper_1 form').submit(function(e){
-
- var FormErrorFlag = false;
- $('.gform_body .form-error').remove();
-
- objCheckFormInputs = {
- 1 : validateAlpha($('.gform_body > ul > li').eq(1).find('input').val()),
- 2 : validateAlpha($('.gform_body > ul > li').eq(2).find('input').val()),
- 3: isEmpty($('.gform_body > ul > li').eq(3).find('input').val()),
- 5: validateAlpha($('.gform_body > ul > li').eq(5).find('input').val()),
- 6: validateAlpha($('.gform_body > ul > li').eq(6).find('input').val()),
- 7: validateNumber($('.gform_body > ul > li').eq(7).find('input').val()),
- 10: validateNumber($('.gform_body > ul > li').eq(10).find('input').val()) && validateMinAlphaLength($('.gform_body > ul > li').eq(10).find('input').val() , 6),
- 12: validateEmail($('.gform_body > ul > li').eq(12).find('input').val())
- }
- $.each( objCheckFormInputs , function(key , val){
- if(val === false) {
- FormErrorFlag = true,
- ErrorText = $('.gform_body > ul > li').eq(key).find('label').text().replace(/\*$/ , '');
- $('.gform_body > ul > li')
- .eq(key)
- .find('input')
- .parent()
- .append('<div class="form-error">This field is required</div>');
- }
- });
- if(FormErrorFlag) {
- e.preventDefault();
- e.stopPropagation();
- }
-
- });
as you can see the event is only prevented if the form validation sets FormErrorFlag to false I.E. the below line of code:
- if(FormErrorFlag) {
- e.preventDefault();
- e.stopPropagation();
- }
My question is , is this a race condition of sorts ?, because the form submit event will only be prevented if the form validation does't pass.
Note:: i cannot use Ajax for form submission as this is for a CMS platform that only needs the form to be prevented form submission if the validation fails.
Thank you.
Gautam.