Read-Only Attachment

Hi,

I have an attachment field under a tab and I would like to display this field as a Lookup - read-only field.

I have other fields that work great as 'Read Only' fields but the attachment field doesn't seem to be working.

This is for a single line of text field which is displayed as Read-Only in my review Wizard:

   fd.field('RNewEmailAddress').disabled = true
	fd.field('New_Email_Address').$on('change', function() {
 	fd.field('RNewEmailAddress').value = fd.field('New_Email_Address').value; 
	})

I would like to do the same thing for an attachment field where Users can only see the file they have attached.

Thank you!

@DryChips,

The code below should work for the Attachments field.

fd.field('Attachments').disabled = true;

If you want to change the appearance of the field, use CSS styling.

Hi,

This code doesn't seem to have worked:

fd.field('RProofName').disabled = true;
    fd.field('Attachments').$on('change', function() {
 	fd.field('RProofName').value = fd.field('Attachments').value; 
	})

@DryChips,

I don't understand what exactly you want to do with the Attachment field.

Do you want pass file names to another field? For this you need to get each file name separately and then populate the field:

var fileNames = [];
fd.field('Attachments').value.forEach(function(f){ 
    fileNames.push(f.name);
})
//convert array to string and populate field
fd.field('fieldName').value = fileNames.join('; ')

Hi,

I want to take the file name from the attachments field and pass its name to a single line text field and display it as read-only.

I have tested the code you have provided and it works great! The problem I'm having now is running this inside the fd.spRendered(function()

Oddly enough, the code runs in Browser console but not in Plumsails JS editor.

Here is how the code is laid out: The Attachment code is all the the way at the bottom for testing purposes.

fd.spRendered(function() {
    
    fd.field('RERostering').disabled = true
	fd.field('Question_1').$on('change', function() {
 	fd.field('RERostering').value = fd.field('Question_1').value; 
	})
    
    fd.field('RDetailsChange').disabled = true
	fd.field('Question_2').$on('change', function() {
 	fd.field('RDetailsChange').value = fd.field('Question_2').value; 
	})
          
    fd.field('RSupervisorName').disabled = true
	fd.field('Supervisor_Name').$on('change', function() {
 	fd.field('RSupervisorName').value = fd.field('Supervisor_Name').value; 
	})
        
    fd.field('RSupervisorEmail').disabled = true
	fd.field('Supervisor_Email_Address').$on('change', function() {
 	fd.field('RSupervisorEmail').value = fd.field('Supervisor_Email_Address').value; 
	})

	fd.field('RTitle').disabled = true
	fd.field('Titles').$on('change', function() {
 	fd.field('RTitle').value = fd.field('Titles').value; 
	})
    
    fd.field('RFirstName').disabled = true
	fd.field('First_Name').$on('change', function() {
 	fd.field('RFirstName').value = fd.field('First_Name').value; 
	})
    
    fd.field('RLastName').disabled = true
	fd.field('Last_Name').$on('change', function() {
 	fd.field('RLastName').value = fd.field('Last_Name').value; 
	})
    
    fd.field('RAssignNum').disabled = true
	fd.field('Assignment_Number').$on('change', function() {
 	fd.field('RAssignNum').value = fd.field('Assignment_Number').value; 
	})
    
    fd.field('RPayBand').disabled = true
	fd.field('Pay_Band').$on('change', function() {
 	fd.field('RPayBand').value = fd.field('Pay_Band').value; 
	})
    
    fd.field('RCurrentHours').disabled = true
	fd.field('Current_Hours').$on('change', function() {
 	fd.field('RCurrentHours').value = fd.field('Current_Hours').value; 
	})
    
    fd.field('RHospital').disabled = true
	fd.field('Hospital').$on('change', function() {
 	fd.field('RHospital').value = fd.field('Hospital').value.LookupValue; 
	})
    
    fd.field('RDivision').disabled = true
	fd.field('Division').$on('change', function() {
 	fd.field('RDivision').value = fd.field('Division').value.LookupValue; 
	})
    
    fd.field('RCostCentreCode').disabled = true
	fd.field('Cost_Centre_Code').$on('change', function() {
 	fd.field('RCostCentreCode').value = fd.field('Cost_Centre_Code').value; 
	})
    
    fd.field('RStaffGroup').disabled = true
	fd.field('Main_Staff_Group').$on('change', function() {
 	fd.field('RStaffGroup').value = fd.field('Main_Staff_Group').value; 
	})
    
    fd.field('RNewName').disabled = true
	fd.field('New_Name').$on('change', function() {
 	fd.field('RNewName').value = fd.field('New_Name').value; 
	})

    fd.field('RNewPhoneNumber').disabled = true
	fd.field('New_Phone_Number').$on('change', function() {
 	fd.field('RNewPhoneNumber').value = fd.field('New_Phone_Number').value; 
	})
    
    fd.field('RNewEmailAddress').disabled = true
	fd.field('New_Email_Address').$on('change', function() {
 	fd.field('RNewEmailAddress').value = fd.field('New_Email_Address').value; 
	})
    
    fd.field('RHomeAddress1').disabled = true
	fd.field('Home_Address1').$on('change', function() {
 	fd.field('RHomeAddress1').value = fd.field('Home_Address1').value; 
	})
        
    fd.field('RHomeAddress2').disabled = true
	fd.field('Home_Address2').$on('change', function() {
 	fd.field('RHomeAddress2').value = fd.field('Home_Address2').value; 
	})
    
    fd.field('RHomeCity').disabled = true
	fd.field('Home_Address_City').$on('change', function() {
 	fd.field('RHomeCity').value = fd.field('Home_Address_City').value; 
	})
    
    fd.field('RHomeCounty').disabled = true
	fd.field('Home_Address_County').$on('change', function() {
 	fd.field('RHomeCounty').value = fd.field('Home_Address_County').value; 
	})
    
    fd.field('RHomePostcode').disabled = true
	fd.field('Home_Address_Postcode').$on('change', function() {
 	fd.field('RHomePostcode').value = fd.field('Home_Address_Postcode').value; 
	})
    
    fd.field('REmergencyContact').disabled = true
	fd.field('Emergency_Contact_Name').$on('change', function() {
 	fd.field('REmergencyContact').value = fd.field('Emergency_Contact_Name').value; 
	})
    
    fd.field('REmergencyRelationship').disabled = true
	fd.field('Emergency_Relationship').$on('change', function() {
 	fd.field('REmergencyRelationship').value = fd.field('Emergency_Relationship').value; 
	})
    
    fd.field('REmergencyPhone1').disabled = true
	fd.field('Emergency_Phone1').$on('change', function() {
 	fd.field('REmergencyPhone1').value = fd.field('Emergency_Phone1').value; 
	})
    
    fd.field('REmergencyPhone2').disabled = true
	fd.field('Emergency_Phone2').$on('change', function() {
 	fd.field('REmergencyPhone2').value = fd.field('Emergency_Phone2').value; 
	})
    
    fd.field('REmergencyAddress1').disabled = true
	fd.field('Emergency_Address1').$on('change', function() {
 	fd.field('REmergencyAddress1').value = fd.field('Emergency_Address1').value; 
	})
    
    fd.field('REmergencyAddress2').disabled = true
	fd.field('Emergency_Address2').$on('change', function() {
 	fd.field('REmergencyAddress2').value = fd.field('Emergency_Address2').value; 
	})
    
    fd.field('REmergencyCity').disabled = true
	fd.field('Emergency_Contact_City').$on('change', function() {
 	fd.field('REmergencyCity').value = fd.field('Emergency_Contact_City').value; 
	})
    
    fd.field('REmergencyCounty').disabled = true
	fd.field('Emergency_Contact_County').$on('change', function() {
 	fd.field('REmergencyCounty').value = fd.field('Emergency_Contact_County').value; 
	})
    
    fd.field('REmergencyPostcode').disabled = true
	fd.field('Emergency_Contact_Postcode').$on('change', function() {
 	fd.field('REmergencyPostcode').value = fd.field('Emergency_Contact_Postcode').value; 
	})
    
    var fileNames = [];
    fd.field('Attachments').value.forEach(function(f){ 
    fileNames.push(f.name);
    })
    fd.field('Text10').disabled = true
    fd.field('Text10').value = fileNames.join('; ')
    
});

@DryChips,

Check the browser console for the errors. Perhaps there is invalid field name in the code.

Hmmm, not seem to have worked.

@DryChips,

Try adding the ready() event, to make sure that the Attachments field is fully loaded:

var fileNames = [];
fd.field('Attachments').ready().then(function(){
    fd.field('Attachments').value.forEach(function(f){ 
        fileNames.push(f.name);
    })
    fd.field('Field1').disabled = true
    //convert array to string and populate field
    fd.field('Field1').value = fileNames.join('; ')
});

Hi mnikitina,

The code seems to be working in console. How do I make it run 'on Change' of a field?

Hello @DryChips,

Try out this code:

var fileNames = [];
fd.field('Attachments').ready().then(function(){
    fd.field('Attachments').$on('change', function(value) {
        value.forEach(function(f){ 
            fileNames.push(f.name);
        });
    })
    fd.field('Field1').disabled = true
    //convert array to string and populate field
    fd.field('Field1').value = fileNames.join('; ')
});

Hi,

This is what I get in the console:

image

Still can't see the file name in Text 10 field.

Hello @DryChips,

I'm sorry, this is my mistake, I shared the incorrect code. Please try out this one:

fd.spRendered(function() {
    var fileNames = [];
    fd.field('Text1').disabled = true;

    fd.field('Attachments').ready().then(function() {
        fd.field('Attachments').$on('change', function(value) {
            value.forEach(function(f) {
                fileNames.push(f.name);
            });
            //convert array to string and populate field
            fd.field('Text1').value = fileNames.join('; ')
        })

    });
});
1 Like

Awesome! This is perfect. Thanks as always. :slight_smile:

1 Like