Multiple drop-down field validation

Hi All

Is there an easy way to validate multiple drop-down values against each other to avoid duplicate values, therefore ensuring that all four values are unique?

We are asking students to select a single choice from 4 drop-down field options that are populated with the same list of subjects.

First Choice = Subject
Second Choice = Subject
Third Choice = Subject
Reserve Choice = Subject

It would take a lot of individual validations to check each drop-down value against one another, just hoping that there is a loop or a simple mechanism that can be applied to ensure the same subject isn't selected more than once.

Each of the option choices are in the same grid.

Thanks in advance for any guidance.

Regards

Mark

Dear @mloveridge,
Yes, if each field is a single-choice, it should be easily solved with just one validator, something like this should work:

fd.validators.push({
    name: 'CoursesValidator',
    error: "Please, select unique courses",
    validate: function(value) {
        if (fd.field('Field1').value == fd.field('Field2').value || fd.field('Field1').value == fd.field('Field3').value || fd.field('Field1').value == fd.field('Field4').value || fd.field('Field2').value == fd.field('Field3').value || fd.field('Field2').value == fd.field('Field4').value || fd.field('Field3').value == fd.field('Field4').value)
            return false;

        return true;
    }
});

@Nikita_Kurguzov

If I understand correctly then the 'If' statement will still have four validation checks.

fd.field('stFirstChoice').value == fd.field('stSecondChoice').value || fd.field('stFirstChoice').value == fd.field('stThirdChoice').value || fd.field('stFirstChoice').value == fd.field('stReserveChoice').value ||
		
fd.field('stSecondChoice').value == fd.field('stFirstChoice').value || fd.field('stSecondChoice').value == fd.field('stThirdChoice').value || fd.field('stSecondChoice').value == fd.field('stReserveChoice').value ||
		 
fd.field('stThirdChoice').value == fd.field('stFirstChoice').value || fd.field('stThirdChoice').value == fd.field('stSecondChoice').value || fd.field('stThirdChoice').value == fd.field('stReserveChoice').value) ||

fd.field('stReserveChoice').value == fd.field('stFirstChoice').value || fd.field('stReserveChoice').value == fd.field('stSecondChoice').value || fd.field('stReserveChoice').value == fd.field('stThirdChoice').value)

Each line would take the source field and check against the remaining three fields to see if there was a match, if there was throw error on form submission.

Regards

Mark

Dear @mloveridge,
Not quite, you can combine all checks into one if condition, and then you don't need to check all of these as some of them repeat.

For example, this:
fd.field('stFirstChoice').value == fd.field('stSecondChoice').value
is the same as this:
fd.field('stSecondChoice').value == fd.field('stFirstChoice').value
so you you don't need to check it twice.

@Nikita_Kurguzov

Okay I understand the logic you are referencing.

I have added the following code to the public form

fd.validators.push({
    name: 'CoursesValidator',
    error: "Please, select unique courses",
    validate: function(value) {
        if (fd.field('stFirstChoice').value == fd.field('stSecondChoice').value || fd.field('stFirstChoice').value == fd.field('stThirdChoice').value || fd.field('stFirstChoice').value == fd.field('stReserveChoice').value || fd.field('stSecondChoice').value == fd.field('stThirdChoice').value || fd.field('stSecondChoice').value == fd.field('stReserveChoice').value || fd.field('stThirdChoice').value == fd.field('stReserveChoice').value) {
        return false;
    }
        return true;
    }
});

However it doesn't show any error responses when selecting two or more like fields, your initial code look to be missing some curly braces so I hope what I have above is the right syntax.

Regards

Mark

Dear @mloveridge,
Looks correct, should work. Make sure it's wrapped inside fd.rendered() event. If it doesn't work - would you be able to export the form? If you don't want to share it here, you can send it to support@plumsail.com and we'll take a look at it.