This topic is locked
[SOLVED]

Disable Attachment field

6/28/2024 5:41:03 AM
PHPRunner General questions
P
PK author

Based on the user logged in, I enable or deisable access to add an attachement using this code in JS Onload:

var ctrlMod = Runner.getControl(pageid,'AttachmentModerator');
ctrlMod.setDisabled();

This prevents the user from adding an attachment but he can still delete the existing attachment
img alt
How do I disable those radio buttons too

Thanks
Percy

P
PK author 7/16/2024

Since I posted this close to 3 weeks ago, I have searched and searched without success for a solution.

If there is no solution to this currently, can it probably to looked into in future updates.

Thank you

mbintex 7/16/2024

Why don“t you just hide the complete field it certain users are logged in?

P
PK author 7/16/2024

Thanks mbintex,
I considered that, but I want the user to be able to open/download the attachment but not be able update or delete the attachement.

C
cristi 7/16/2024

If those are the only radio buttons on your page you could search them all and hide in javascript onload event of your page:

var btns = document.querySelectorAll('input[type=radio]')
for(var i=0;i<btns.length;i++){

btns[i].setAttribute('style', 'display:none'); //remove radio button
btns[i].nextSibling.textContent = ''; //set text to empty

}

img alt

P
PK author 7/16/2024

Thanks cristi, brilliant idea!
But there are 3 attachment fields on the page and only one is accessible to any logged in user, the other 2 are view only.
So using your method, is there way to get the control name or ID in the loop so I can exclude which one should not be disabled

Thanks
PK

C
cristi 7/17/2024

Upload controls are grouped in divs.
If you open web developer tools in firefox and search for the div that you want to disable radio controls it will have a data-fieldname attribute which is the same as the field name in database (I have an upload field in the database that I named "file"):

img alt

Now change the code posted before like this (two choices for finding radio buttons in divs - you decide...):

var btns = document.querySelectorAll('[data-fieldname="file"] input[type=radio]'); //this finds all divs with data-fieldname attribute "file" AND radio buttons

var btns = document.querySelectorAll('[data-fieldname]:not([data-fieldname="file"]) input[type=radio]'); //or if you want to exclude div with data-fieldname "file"

for(var i=0;i<btns.length;i++){

btns[i].setAttribute('style', 'display:none'); //remove radio button
btns[i].nextSibling.textContent = ''; //set text to empty

}

Repeat the code for first btns div with another field name or use the second btns code to exclude one div - your choice

P
PK author 7/17/2024

cristi, Your solution worked perfectly!
Thanks so so much

PK