Validation alert if two people fields are the same

Hello,

I have two people fields on my form that should not equal the same. If they do, the form should either not let you save or the user should receive a validation error. The requirement is that you should not be able to choose the "creator" of the form in another person text field. I cannot figure how to do this.

I was able to get validation in the form however, it is causing a validation error no matter if the fields are different or the same.

Here is the code I used:
fd.rendered(function() {
fd.field('ApprovingMgrSupvr').addValidator({
name: 'Different Approver',
error: 'The Approving Manager and form Submitter must be different',
validate: function(value) {
if (fd.field('ApprovingMgrSupvr').value !== fd.field('LoggedIn').value) {
return false;
}
return true;
}
});
});

Any help would be very appreciated!

Thank you

Dear @erob123,
Try it like this:

fd.spRendered(function() {
    fd.field('ApprovingMgrSupvr').addValidator({
        name: 'Different Approver',
        error: 'The Approving Manager and form Submitter must be different',
        validate: function(value) {
            if (fd.field('ApprovingMgrSupvr').value == fd.field('LoggedIn').value) {
                return false;
            }
            return true;
        }
    });
    fd.field('LoggedIn').addValidator({
        name: 'Different LoggedIn',
        error: 'The Approving Manager and form Submitter must be different',
        validate: function(value) {
            if (fd.field('ApprovingMgrSupvr').value == fd.field('LoggedIn').value) {
                return false;
            }
            return true;
        }
    });
});

It's important to use fd.spRendered() and not fd.rendered() in this case, you also want validation on both fields, and the condition must return false when it's not what you want it to be.

Thank you so much. This worked for the New Form. It does not seem to work for the Edit Form. Should it work the same way?

Dear @erob123,
Yes, there should be no difference. Check browser's console for errors on the Edit form.