Block submit condition if error in validation

Hi Plumsail! I have a problem in edit form.
I have a custom button added in form with a code that changes the value of a specific field on click, then saves the form.

var submitButton = {
text: 'Submit',
location: 0,
click: function() {
if (fd.field('txtStatus').value == 'New' ){
fd.field('txtStatus').value ='In progress';
fd.save();
}
else if (fd.field('txtStatus').value == ''In progress'){
fd.field('FormStatus').value = 'Success';
fd.save();
}
}
}

The problem is when it has a required validation error on save, the value of txtStatus field changes already. How can I add a validation that will only change the txtStatus field, if it has no error in all validation during save.

Thanks!

Hello @Jes_Santimosa,

You can add a condition to check whether the form is valid:

//check the form is valid
if (fd.isValid) {
    if (fd.field('txtStatus').value == 'New') {
        fd.field('txtStatus').value = 'In progress';
        fd.save();
    } else if (fd.field('txtStatus').value == 'In progress'){
        fd.field('FormStatus').value = 'Success'; 
        fd.save();
    }
}
}
1 Like

Problem solved. Thank you!

1 Like