Conditional Date and Name entries

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

07 Jun 2018

Code to configure custom JS validation as requested by TKey here - https://community.plumsail.com/t/condit ... tries/6649

Hope this helps! Let me know how it goes!

Code: Select all

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


//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().length){
            fd.field('SemifinalDate').readonly(true);
            fd.field('SemifinalDate').value('');
            return false;
        }
    }
    
    fd.field('SemifinalDate').readonly(false);
}

//function to disable/enable final fields
function enableDisableFinal(){
    if(fd.field('SemifinalDate').value()){
        fd.field('DateFinal').readonly(false);
        fd.field('UserFinal').readonly(false);
    }
    else{
        fd.field('DateFinal').value('');
        fd.field('UserFinal').value('');
        fd.field('DateFinal').readonly(true);
        fd.field('UserFinal').readonly(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]).change(function() {
        enableDisableSemifinal();
    });
}

//on change in semifinal date, check if final fields can be enabled
fd.field('SemifinalDate').change(function() {
    enableDisableFinal();
});

//checks on form load
enableDisableSemifinal();
enableDisableFinal();

fd.onsubmit(function(){
    if (fd.field('Date1').value() && !fd.field('User1').value().length) {
           alert('"Date1" and "User1" must be input together.');
           return false;
    }
    else if (!fd.field('Date1').value() && fd.field('User1').value().length) {
           alert('"Date1" and "User1" must be input together.');
           return false;
    }
    
    if (fd.field('Date2').value() && !fd.field('User2').value().length) {
           alert('"Date2" and "User2" must be input together.');
           return false;
    }
    else if (!fd.field('Date2').value() && fd.field('User2').value().length) {
           alert('"Date2" and "User2" must be input together.');
           return false;
    }
    
    if (fd.field('Date3').value() && !fd.field('User3').value().length) {
           alert('"Date3" and "User3" must be input together.');
           return false;
    }
    else if (!fd.field('Date3').value() && fd.field('User3').value().length) {
           alert('"Date3" and "User3" must be input together.');
           return false;
    }
    
    if (!fd.field('DateFinal').readonly() && fd.field('DateFinal').value() && !fd.field('UserFinal').value().length) {
           alert('"DateFinal" and "UserFinal" must be input together.');
           return false;
    }
    else if (!fd.field('DateFinal').readonly() &&  !fd.field('DateFinal').value() && fd.field('UserFinal').value().length) {
           alert('"DateFinal" and "UserFinal" must be input together.');
           return false;
    }
    
    for (var i = 0; i < fieldNames.length; i++){
        fd.field(fieldNames[i]).readonly(false);
    }
    fd.field('SemifinalDate').readonly(false);
    fd.field('DateFinal').readonly(false);
    fd.field('UserFinal').readonly(false);
    return true;

});
Cheers

TK
Posts: 5
Joined: Fri Jun 08, 2018

08 Jun 2018

Nikita,
Thank you very much! Tis is exactly what I needed.
Best,
TK

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests