How to Hide or show List or Library control

//Required Upload
fd.spRendered(function() {
	
fd.validators;

fd.validators.push({
    name: 'MyCustomValidator',
    error: 'Add a record to a child table',
    validate: function(value) {
        if (fd.control('SPDataTable2').widget.dataItems().length < 1
        && fd.field('LineManagerApproval').value == 'Yes')
            return false;

        return true;
    }
});

});

I tried using the above code and I am not getting the error message. Please help. What am I doing wrong?

Hi,

You were missing the curly brackets after testing the condition.

Try this:

//Required Upload
fd.spRendered(function() {
	
fd.validators;

	fd.validators.push({
    		name: 'MyCustomValidator',
    		error: 'Add a record to a child table',
    		validate: function(value) {
        			if (fd.control('SPDataTable2').widget.dataItems().length < 1
        			&& fd.field('LineManagerApproval').value == 'Yes'){
				return false;
				}
            			return true;
    			}
	});

});

Hello @Jamail_Serio,

Most likely something is wrong in the condition.

Please double check field and control internal names. Also, what is the type of the LineManagerApproval field?

Hello @Qman,

Thank you for your suggestion. In this case curly brackets are not necessary.

1 Like

Hi @mnikitina I am trying to hide the list or library control if there is no item in that, using the code below. Any suggestions since it is not working:

fd.spRendered(function() {
    
   
    function filterDT(){
        dt.filter = "<Contains><FieldRef Name='FileLeafRef'/><Value Type='Text'>"
            + fd.field('sysid').value + "</Value></Contains>";
        dt.refresh();
    }
   
   
     var dt = fd.control('ListOrLibrary1');
    dt.ready(function() {
        
        filterDT();
        
    }); 
    
    //hide list or ListOrLibrary

fd.control('ListOrLibrary1').ready(function(dt) {
        //dt parameter is the same as fd.control('Control1')
        console.log('List or Library is initialized');
        if (fd.control('ListOrLibrary1').widget.dataItems().length < 1){
    
            fd.control('ListOrLibrary1').hidden = true;
           } else {
         fd.control('ListOrLibrary1').hidden = false;
           }
    });
  
});

@aseem,

You can use the setTimeout() function like so:

fd.spRendered(function() {
	var dt = fd.control('ListOrLibrary1');
	dt.ready(function() {
		filterDT();
		setTimeout(() => {
			if (fd.control('ListOrLibrary1').widget.dataSource.data().length < 1) {
				fd.control('ListOrLibrary1').hidden = true;
			} else {
				fd.control('ListOrLibrary1').hidden = false;
			}
		}, "1000");
	});

	function filterDT() {
		dt.filter = "<Contains><FieldRef Name='FileLeafRef'/><Value Type='Text'>" + fd.field('sysid').value + "</Value></Contains>";
		dt.refresh()
	}
});

Also, is FileLeafRef is the internal name of the column? Make sure it is, otherwise you will get an error.

Thank you this worked! FileLeafRef is the file name. I am adding the filter based on file name.

1 Like