Attachment field Read Only

I am trying to make attachment field readonly if certain condition is true. I am using code

if (fd.field('Submit').value == true)
{
fd.field('Attachments').readonly(true);
}

I tried fd.field('Attachments').readonly = true as well but it didnt work. How can I make it readonly programmatically?

Hello @Ramiz,

You can disable Attachments field using this code:

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

Hi @mnikitina

I have tried this as well but this is disabling the attachments. I can see the attachments but cant download. I need the read only as it is in display form where I cannot add files but can download and view the files.

Hello @Ramiz,

You can hide 'Select files' and delete buttons of the attachemnts field, making it look like readonly mode, using this code:

fd.spRendered(function() {
        var at = $(fd.field('Attachments').$el)
        $(at).find('.k-upload .k-upload-button').hide()
        $('.k-upload-action').hide();
});

Thank you so much @mnikitina. It worked.

1 Like

Hi @mnikitina
The 'Select files' and delete buttons are disabled but still I am able to attach files. If I click under attachments the window opens and I can attach. It should not attach files if it is read only.

Demo

Hello @Ramiz,

Thank you for the video!

You can add this code line to disable the upload option:

$('input[type=file]').prop( "disabled", true ); 

Thus, the complete code to make the Attachments field behave as read-only is:

fd.spRendered(function() {
        var at = $(fd.field('Attachments').$el)
        $(at).find('.k-upload .k-upload-button').hide()
        $('.k-upload-action').hide();
        $('input[type=file]').prop( "disabled", true );
});
1 Like

Thank you so much @mnikitina. It works.

1 Like