Conditional Date and Name entries

Hi there,
I need some help with field validations / conditions. In my form I have a multiple date and person fields where users enter their names and dates when milestones are reached. I would like to enforce that when the date is entered in a field, "completed by" name must also be entered next to it, and vice versa when user enter their name first then the date must be entered.
Also the last two fields "kick-off meeting held" and "Project setup completed and closed" cannot be filled out unless all other fields are entered/filled out...

Thanks,
TK

Dear @TKey,
We can help you with the code, write an example for you, just let us know if you want dates to be chronological from Top to Bottom or is it not important? And should field3 be editable, if field1 and field2 are empty?

Also, regarding final field with date and user (Project setup…) - should it be disabled until Kick-off meeting is complete or all three fields (2 dates and one people picker) be available when other dates are completed.

Finally, disabling and enabling last fields can be done either dynamically, as user inputs values into other fields on the form, or only once when the form opens - it will check values of all fields and determine if it needs to disable or enable final fields. Which would work best for your case?

Dear Nikita,
Thank you very much for helping me, you guys are awesome!

1. dates to be chronological from Top to Bottom or is it not important?
The dates actually are not entered in a chronological order.

2. And should field3 be editable, if field1 and field2 are empty?
Yes, field3 should be editable even if field1 and field2 are empty, all besides the last one should be editable.

3. Also, regarding final field with date and user (Project setup…) - should it be disabled until Kick-off meeting is complete or all three fields (2 dates and one people picker) be available when other dates are completed.
Yes, actually the final field should be disabled until kick-off meteg is complete / date entered

4. Finally, disabling and enabling last fields can be done either dynamically, as user inputs values into other fields on the form, or only once when the form opens - it will check values of all fields and determine if it needs to disable or enable final fields. Which would work best for your case?
I think disabling them dynamically would work best in this case

Thank you again!

Dear @TKey,
I wrote the code for lesser amount of fields, but it should still work. All you have to do, is add InternalNames of your fields to the fieldNames array in the beginning and replace field names in other places they are used, such as Semifinal_x0020_Date, for example. Finally, I didn’t write a loop for validators, so you can see how they work - you can either write your own loop for them, or simply add the missing ones.

//Internal Names of the fields that have to be filled in first
var fieldNames = ['Date1', 'Date2', 'Date3', 'User1', 'User2', 'User3'];

fd.spRendered(function(){
    //function to disable/enable Kick off meeting date field
    function enableDisableSemifinal(){
        //loop through all fields in fieldNames array and if one is missing value - disable semifinal
        for (var i = 0; i < fieldNames.length; i++){
            if(!fd.field(fieldNames[i]).value){
                fd.field('Semifinal_x0020_Date').disabled = true;
                $(fd.field('Semifinal_x0020_Date').$el).find('a').hide();
                fd.field('Semifinal_x0020_Date').value = '';
                return false;
            }
        }
        
        fd.field('Semifinal_x0020_Date').disabled = false;
        $(fd.field('DateFinal').$el).find('a').show();
    }
    
    //function to disable/enable final fields
    function enableDisableFinal(){
        if(fd.field('Semifinal_x0020_Date').value){
            fd.field('DateFinal').disabled = false;
            $(fd.field('DateFinal').$el).find('a').show();
            fd.field('UserFinal').disabled = false;
        }
        else{
            fd.field('DateFinal').value = '';
            fd.field('UserFinal').value = '';
            fd.field('DateFinal').disabled = true;
            $(fd.field('DateFinal').$el).find('a').hide();
            fd.field('UserFinal').disabled = true;
        }
    }
    
    //each time there is a change to one of the fields - check if semifinal date can be enabled
    for (var i = 0; i < fieldNames.length; i++){
        fd.field(fieldNames[i]).$on('change', function(value) {
            enableDisableSemifinal();
        });
    }
    
    //on change in semifinal date, check if final fields can be enabled
    fd.field('Semifinal_x0020_Date').$on('change', function(value) {
        enableDisableFinal();
    });
    
    //checks on form load
    enableDisableSemifinal();
    enableDisableFinal();
    

    //validators, need to add the missing ones
    fd.validators.push(
    {
        name: 'Date1 Validator',
        error: '"Date1" and "User1" must be input together.',
        validate: function(value) {
            if (fd.field('Date1').value && !fd.field('User1').value)
                return false;
            else if (!fd.field('Date1').value && fd.field('User1').value)
                return false;
                
            return true;
        }
    },
    {
        name: 'Date2 Validator',
        error: '"Date2" and "User2" must be input together.',
        validate: function(value) {
            if (fd.field('Date2').value && !fd.field('User2').value)
                return false;
            else if (!fd.field('Date2').value && fd.field('User2').value)
                return false;
                
            return true;
        }
    },
    {
        name: 'Date3 Validator',
        error: '"Date3" and "User3" must be input together.',
        validate: function(value) {
            if (fd.field('Date3').value && !fd.field('User3').value)
                return false;
            else if (!fd.field('Date3').value && fd.field('User3').value)
                return false;
                
            return true;
        }
    },
    {
        name: 'Final Date Validator',
        error: '"DateFinal" and "UserFinal" must be input together.',
        validate: function(value) {
            if (fd.field('DateFinal').value && !fd.field('UserFinal').value)
                return false;
            else if (!fd.field('DateFinal').value && fd.field('UserFinal').value)
                return false;
                
            return true;
        }
    }
    );
});

Hi Nikita,
Thank you very much for the code. I am having a hard time to make it work on my end. Do I need a specific version of the Forms to make it work? It seems that spRendered is not doing anything at all…

Uncaught TypeError: fd.spRendered is not a function

Dear TKey,
Are you using Forms or Forms Designer? This code is specifically for Forms, and it wouldn’t work with Forms Designer.

Hi Nikita,
I do use Forms Designer for SharePoint 2013
Best,
TK

Dear Tkey,
Okay, we’ll help with Forms Designer as well, but just for the future, these questions are better answered in the official Forms Designer forum here - https://spform.com/forum/

This forum is designated for Forms first and foremost.

Nikita,
Thank you very much. Next time I will make sure to post my questions in the Forms Designer forum…
Best,
TK

Dear TKey,
Here you go, I’ve provided the same code adjusted for Forms Designer - https://spform.com/forum/viewtopic.php?f=1&t=2094